|
| 1 | +import { Buffer } from "buffer"; |
| 2 | +import type { Option, u32, u64 } from "@stellar/stellar-sdk/contract"; |
| 3 | +import { |
| 4 | + type AssembledTransaction, |
| 5 | + Client as ContractClient, |
| 6 | + type ClientOptions as ContractClientOptions, |
| 7 | + type MethodOptions, |
| 8 | + type Result, |
| 9 | + Spec as ContractSpec, |
| 10 | +} from "@stellar/stellar-sdk/contract"; |
| 11 | + |
| 12 | +export * from "@stellar/stellar-sdk"; |
| 13 | +export * as contract from "@stellar/stellar-sdk/contract"; |
| 14 | +export * as rpc from "@stellar/stellar-sdk/rpc"; |
| 15 | + |
| 16 | +if (typeof window !== "undefined") { |
| 17 | + //@ts-ignore Buffer exists |
| 18 | + globalThis.Buffer = globalThis.Buffer || Buffer; |
| 19 | +} |
| 20 | + |
| 21 | +export const RegistryV2Errors = { |
| 22 | + 300: { message: "UnexpectedError" }, |
| 23 | + 301: { message: "InvalidDomain" }, |
| 24 | + 302: { message: "InvalidSubDomain" }, |
| 25 | + 303: { message: "UnsupportedTLD" }, |
| 26 | + 304: { message: "DomainAlreadyExist" }, |
| 27 | + 305: { message: "PaymentFailed" }, |
| 28 | + 306: { message: "MintingTokenFailed" }, |
| 29 | + 307: { message: "RecordDoesntExist" }, |
| 30 | + 308: { message: "RecordIsExpired" }, |
| 31 | + 309: { message: "BurningTokenFailed" }, |
| 32 | + 310: { message: "RecordCantBeClaimedYet" }, |
| 33 | + 311: { message: "V1DomainRegistered" }, |
| 34 | + 312: { message: "InvalidV1Domain" }, |
| 35 | + 313: { message: "V1DomainMigrationExpired" }, |
| 36 | +}; |
| 37 | + |
| 38 | +export interface Domain { |
| 39 | + address: string; |
| 40 | + domain: Buffer; |
| 41 | + exp_date: u64; |
| 42 | + node: Buffer; |
| 43 | + snapshot: u64; |
| 44 | + tld: Buffer; |
| 45 | + token_id: u32; |
| 46 | +} |
| 47 | + |
| 48 | +export type RecordKey = { tag: "Domain"; values: readonly [Buffer] } | { |
| 49 | + tag: "SubDomain"; |
| 50 | + values: readonly [Buffer]; |
| 51 | +}; |
| 52 | + |
| 53 | +export interface SubDomain { |
| 54 | + address: string; |
| 55 | + domain: Buffer; |
| 56 | + node: Buffer; |
| 57 | + parent: Buffer; |
| 58 | + root: Buffer; |
| 59 | + snapshot: u64; |
| 60 | +} |
| 61 | + |
| 62 | +export type RegistryStorageKeys = |
| 63 | + | { tag: "Index"; values: void } |
| 64 | + | { tag: "Admin"; values: void } |
| 65 | + | { tag: "Oracle"; values: void } |
| 66 | + | { tag: "PayingAsset"; values: void } |
| 67 | + | { tag: "TLDs"; values: void } |
| 68 | + | { tag: "NFD"; values: void } |
| 69 | + | { tag: "Domain"; values: readonly [Buffer] } |
| 70 | + | { tag: "SubDomain"; values: readonly [Buffer] } |
| 71 | + | { tag: "Treasury"; values: void } |
| 72 | + | { tag: "V1Registry"; values: void } |
| 73 | + | { tag: "V1MaxSnapshot"; values: void } |
| 74 | + | { tag: "V1Deadline"; values: void }; |
| 75 | + |
| 76 | +export interface RegistryV2Client { |
| 77 | + /** |
| 78 | + * Construct and simulate a claim transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 79 | + */ |
| 80 | + claim: ( |
| 81 | + { caller, node, address, periods }: { caller: string; node: Buffer; address: string; periods: u64 }, |
| 82 | + options?: MethodOptions, |
| 83 | + ) => Promise<AssembledTransaction<Result<Domain>>>; |
| 84 | + |
| 85 | + /** |
| 86 | + * Construct and simulate a evict transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 87 | + */ |
| 88 | + evict: ({ node }: { node: Buffer }, options?: MethodOptions) => Promise<AssembledTransaction<Result<void>>>; |
| 89 | + |
| 90 | + /** |
| 91 | + * Construct and simulate a renew transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 92 | + */ |
| 93 | + renew: ( |
| 94 | + { caller, node, periods }: { caller: string; node: Buffer; periods: u64 }, |
| 95 | + options?: MethodOptions, |
| 96 | + ) => Promise<AssembledTransaction<Result<Domain>>>; |
| 97 | + |
| 98 | + /** |
| 99 | + * Construct and simulate a record transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 100 | + */ |
| 101 | + record: ( |
| 102 | + { record_key }: { record_key: RecordKey }, |
| 103 | + options?: MethodOptions, |
| 104 | + ) => Promise<AssembledTransaction<Result<readonly [Domain, Option<SubDomain>]>>>; |
| 105 | + |
| 106 | + /** |
| 107 | + * Construct and simulate a migrate transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 108 | + */ |
| 109 | + migrate: ( |
| 110 | + { new_domain, tld }: { new_domain: Buffer; tld: Buffer }, |
| 111 | + options?: MethodOptions, |
| 112 | + ) => Promise<AssembledTransaction<Result<Domain>>>; |
| 113 | + |
| 114 | + /** |
| 115 | + * Construct and simulate a upgrade transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 116 | + */ |
| 117 | + upgrade: ({ hash }: { hash: Buffer }, options?: MethodOptions) => Promise<AssembledTransaction<null>>; |
| 118 | + |
| 119 | + /** |
| 120 | + * Construct and simulate a register transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 121 | + */ |
| 122 | + register: ( |
| 123 | + { new_domain, tld, owner, address, periods }: { |
| 124 | + new_domain: Buffer; |
| 125 | + tld: Buffer; |
| 126 | + owner: string; |
| 127 | + address: string; |
| 128 | + periods: u64; |
| 129 | + }, |
| 130 | + options?: MethodOptions, |
| 131 | + ) => Promise<AssembledTransaction<Result<Domain>>>; |
| 132 | + |
| 133 | + /** |
| 134 | + * Construct and simulate a withdraw transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 135 | + */ |
| 136 | + withdraw: (options?: MethodOptions) => Promise<AssembledTransaction<null>>; |
| 137 | + |
| 138 | + /** |
| 139 | + * Construct and simulate a parse_domain transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 140 | + */ |
| 141 | + parse_domain: ( |
| 142 | + { domain, tld }: { domain: Buffer; tld: Buffer }, |
| 143 | + options?: MethodOptions, |
| 144 | + ) => Promise<AssembledTransaction<Buffer>>; |
| 145 | + |
| 146 | + /** |
| 147 | + * Construct and simulate a register_sub transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 148 | + */ |
| 149 | + register_sub: ( |
| 150 | + { parent, new_subdomain, address }: { parent: RecordKey; new_subdomain: Buffer; address: string }, |
| 151 | + options?: MethodOptions, |
| 152 | + ) => Promise<AssembledTransaction<Result<SubDomain>>>; |
| 153 | + |
| 154 | + /** |
| 155 | + * Construct and simulate a update_address transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 156 | + */ |
| 157 | + update_address: ( |
| 158 | + { record_key, new_address }: { record_key: RecordKey; new_address: string }, |
| 159 | + options?: MethodOptions, |
| 160 | + ) => Promise<AssembledTransaction<Result<void>>>; |
| 161 | + |
| 162 | + /** |
| 163 | + * Construct and simulate a update_treasury transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. |
| 164 | + */ |
| 165 | + update_treasury: ( |
| 166 | + { new_treasury }: { new_treasury: string }, |
| 167 | + options?: MethodOptions, |
| 168 | + ) => Promise<AssembledTransaction<null>>; |
| 169 | +} |
| 170 | + |
| 171 | +export class RegistryV2Client extends ContractClient { |
| 172 | + // deno-lint-ignore require-await |
| 173 | + static override async deploy<T = RegistryV2Client>( |
| 174 | + /** Constructor/Initialization Args for the contract's `__constructor` method */ |
| 175 | + { new_admin, new_oracle, new_paying_asset, new_tlds, new_nfd, v1_registry }: { |
| 176 | + new_admin: string; |
| 177 | + new_oracle: string; |
| 178 | + new_paying_asset: string; |
| 179 | + new_tlds: Array<Buffer>; |
| 180 | + new_nfd: string; |
| 181 | + v1_registry: string; |
| 182 | + }, |
| 183 | + /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */ |
| 184 | + options: |
| 185 | + & MethodOptions |
| 186 | + & Omit<ContractClientOptions, "contractId"> |
| 187 | + & { |
| 188 | + /** The hash of the Wasm blob, which must already be installed on-chain. */ |
| 189 | + wasmHash: Buffer | string; |
| 190 | + /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */ |
| 191 | + salt?: Buffer | Uint8Array; |
| 192 | + /** The format used to decode `wasmHash`, if it's provided as a string. */ |
| 193 | + format?: "hex" | "base64"; |
| 194 | + }, |
| 195 | + ): Promise<AssembledTransaction<T>> { |
| 196 | + return ContractClient.deploy({ new_admin, new_oracle, new_paying_asset, new_tlds, new_nfd, v1_registry }, options); |
| 197 | + } |
| 198 | + |
| 199 | + constructor(public override readonly options: ContractClientOptions) { |
| 200 | + super( |
| 201 | + new ContractSpec([ |
| 202 | + "AAAABAAAAAAAAAAAAAAAEFJlZ2lzdHJ5VjJFcnJvcnMAAAAOAAAAAAAAAA9VbmV4cGVjdGVkRXJyb3IAAAABLAAAAAAAAAANSW52YWxpZERvbWFpbgAAAAAAAS0AAAAAAAAAEEludmFsaWRTdWJEb21haW4AAAEuAAAAAAAAAA5VbnN1cHBvcnRlZFRMRAAAAAABLwAAAAAAAAASRG9tYWluQWxyZWFkeUV4aXN0AAAAAAEwAAAAAAAAAA1QYXltZW50RmFpbGVkAAAAAAABMQAAAAAAAAASTWludGluZ1R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cnM=", |
| 223 | + "AAAAAAAAAAAAAAANX19jb25zdHJ1Y3RvcgAAAAAAAAYAAAAAAAAACW5ld19hZG1pbgAAAAAAABMAAAAAAAAACm5ld19vcmFjbGUAAAAAABMAAAAAAAAAEG5ld19wYXlpbmdfYXNzZXQAAAATAAAAAAAAAAhuZXdfdGxkcwAAA+oAAAAOAAAAAAAAAAduZXdfbmZkAAAAABMAAAAAAAAAC3YxX3JlZ2lzdHJ5AAAAABMAAAAA", |
| 224 | + "AAAAAAAAAAAAAAAOdXBkYXRlX2FkZHJlc3MAAAAAAAIAAAAAAAAACnJlY29yZF9rZXkAAAAAB9AAAAAJUmVjb3JkS2V5AAAAAAAAAAAAAAtuZXdfYWRkcmVzcwAAAAATAAAAAQAAA+kAAAPtAAAAAAAAB9AAAAAQUmVnaXN0cnlWMkVycm9ycw==", |
| 225 | + "AAAAAAAAAAAAAAAPdXBkYXRlX3RyZWFzdXJ5AAAAAAEAAAAAAAAADG5ld190cmVhc3VyeQAAABMAAAAA", |
| 226 | + ]), |
| 227 | + options, |
| 228 | + ); |
| 229 | + } |
| 230 | + |
| 231 | + public readonly fromJSON: object = { |
| 232 | + claim: this.txFromJSON<Result<Domain>>, |
| 233 | + evict: this.txFromJSON<Result<void>>, |
| 234 | + renew: this.txFromJSON<Result<Domain>>, |
| 235 | + record: this.txFromJSON<Result<readonly [Domain, Option<SubDomain>]>>, |
| 236 | + migrate: this.txFromJSON<Result<Domain>>, |
| 237 | + upgrade: this.txFromJSON<null>, |
| 238 | + register: this.txFromJSON<Result<Domain>>, |
| 239 | + withdraw: this.txFromJSON<null>, |
| 240 | + parse_domain: this.txFromJSON<Buffer>, |
| 241 | + register_sub: this.txFromJSON<Result<SubDomain>>, |
| 242 | + update_address: this.txFromJSON<Result<void>>, |
| 243 | + update_treasury: this.txFromJSON<null>, |
| 244 | + }; |
| 245 | +} |
0 commit comments