Skip to content

Commit 03d7cd3

Browse files
committed
allow opaque xdr types to be initalized via string
1 parent 55ffcff commit 03d7cd3

37 files changed

Lines changed: 333 additions & 134 deletions

src/xdr/generated/account-entry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class AccountEntry extends XdrValue {
9191
numSubEntries: number;
9292
inflationDest: PublicKey | null;
9393
flags: number;
94-
homeDomain: string;
94+
homeDomain: Uint8Array | string;
9595
thresholds: Thresholds | Uint8Array | string;
9696
signers: Signer[];
9797
ext: AccountEntryExt;
@@ -103,7 +103,10 @@ export class AccountEntry extends XdrValue {
103103
this.numSubEntries = input.numSubEntries;
104104
this.inflationDest = input.inflationDest;
105105
this.flags = input.flags;
106-
this.homeDomain = input.homeDomain;
106+
this.homeDomain =
107+
input.homeDomain instanceof Uint8Array
108+
? new TextDecoder("latin1").decode(input.homeDomain)
109+
: input.homeDomain;
107110
this.thresholds =
108111
input.thresholds instanceof Thresholds
109112
? input.thresholds

src/xdr/generated/asset-code.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ abstract class AssetCodeBase extends XdrValue {
5151
});
5252

5353
static assetTypeCreditAlphanum4(
54-
assetCode4: AssetCode4,
54+
assetCode4: AssetCode4 | Uint8Array | string,
5555
): AssetCodeCreditAlphanum4 {
5656
return new AssetCodeCreditAlphanum4(assetCode4);
5757
}
5858

5959
static assetTypeCreditAlphanum12(
60-
assetCode12: AssetCode12,
60+
assetCode12: AssetCode12 | Uint8Array | string,
6161
): AssetCodeCreditAlphanum12 {
6262
return new AssetCodeCreditAlphanum12(assetCode12);
6363
}
@@ -82,9 +82,12 @@ export class AssetCodeCreditAlphanum4 extends AssetCodeBase {
8282
readonly type = "assetTypeCreditAlphanum4" as const;
8383
readonly assetCode4: AssetCode4;
8484

85-
constructor(assetCode4: AssetCode4) {
85+
constructor(assetCode4: AssetCode4 | Uint8Array | string) {
8686
super();
87-
this.assetCode4 = assetCode4;
87+
this.assetCode4 =
88+
assetCode4 instanceof AssetCode4
89+
? assetCode4
90+
: new AssetCode4(assetCode4);
8891
}
8992

9093
get value(): AssetCode4 {
@@ -100,9 +103,12 @@ export class AssetCodeCreditAlphanum12 extends AssetCodeBase {
100103
readonly type = "assetTypeCreditAlphanum12" as const;
101104
readonly assetCode12: AssetCode12;
102105

103-
constructor(assetCode12: AssetCode12) {
106+
constructor(assetCode12: AssetCode12 | Uint8Array | string) {
104107
super();
105-
this.assetCode12 = assetCode12;
108+
this.assetCode12 =
109+
assetCode12 instanceof AssetCode12
110+
? assetCode12
111+
: new AssetCode12(assetCode12);
106112
}
107113

108114
get value(): AssetCode12 {

src/xdr/generated/claimable-balance-id.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ abstract class ClaimableBalanceIdBase extends XdrValue {
3232
},
3333
);
3434

35-
static claimableBalanceIdTypeV0(v0: Hash): ClaimableBalanceIdV0 {
35+
static claimableBalanceIdTypeV0(
36+
v0: Hash | Uint8Array | string,
37+
): ClaimableBalanceIdV0 {
3638
return new ClaimableBalanceIdV0(v0);
3739
}
3840

@@ -50,9 +52,9 @@ export class ClaimableBalanceIdV0 extends ClaimableBalanceIdBase {
5052
readonly type = "claimableBalanceIdTypeV0" as const;
5153
readonly v0: Hash;
5254

53-
constructor(v0: Hash) {
55+
constructor(v0: Hash | Uint8Array | string) {
5456
super();
55-
this.v0 = v0;
57+
this.v0 = v0 instanceof Hash ? v0 : new Hash(v0);
5658
}
5759

5860
get value(): Hash {

src/xdr/generated/contract-executable.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ abstract class ContractExecutableBase extends XdrValue {
4242
},
4343
);
4444

45-
static contractExecutableWasm(wasmHash: Hash): ContractExecutableWasm {
45+
static contractExecutableWasm(
46+
wasmHash: Hash | Uint8Array | string,
47+
): ContractExecutableWasm {
4648
return new ContractExecutableWasm(wasmHash);
4749
}
4850

@@ -66,9 +68,9 @@ export class ContractExecutableWasm extends ContractExecutableBase {
6668
readonly type = "contractExecutableWasm" as const;
6769
readonly wasmHash: Hash;
6870

69-
constructor(wasmHash: Hash) {
71+
constructor(wasmHash: Hash | Uint8Array | string) {
7072
super();
71-
this.wasmHash = wasmHash;
73+
this.wasmHash = wasmHash instanceof Hash ? wasmHash : new Hash(wasmHash);
7274
}
7375

7476
get value(): Hash {

src/xdr/generated/data-entry.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ export class DataEntry extends XdrValue {
4646

4747
constructor(input: {
4848
accountId: PublicKey;
49-
dataName: string;
49+
dataName: Uint8Array | string;
5050
dataValue: DataValue | Uint8Array | string;
5151
ext: DataEntryExt;
5252
}) {
5353
super();
5454
this.accountId = input.accountId;
55-
this.dataName = input.dataName;
55+
this.dataName =
56+
input.dataName instanceof Uint8Array
57+
? new TextDecoder("latin1").decode(input.dataName)
58+
: input.dataName;
5659
this.dataValue =
5760
input.dataValue instanceof DataValue
5861
? input.dataValue

src/xdr/generated/error.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,13 @@ export class Error extends XdrValue {
2727
msg: string_(100),
2828
});
2929

30-
constructor(input: { code: ErrorCode; msg: string }) {
30+
constructor(input: { code: ErrorCode; msg: Uint8Array | string }) {
3131
super();
3232
this.code = input.code;
33-
this.msg = input.msg;
33+
this.msg =
34+
input.msg instanceof Uint8Array
35+
? new TextDecoder("latin1").decode(input.msg)
36+
: input.msg;
3437
}
3538

3639
toXdrObject(): ErrorWire {

src/xdr/generated/freeze-bypass-txs-delta.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ export class FreezeBypassTxsDelta extends XdrValue {
2929
},
3030
);
3131

32-
constructor(input: { addTxs: Hash[]; removeTxs: Hash[] }) {
32+
constructor(input: {
33+
addTxs: (Hash | Uint8Array | string)[];
34+
removeTxs: (Hash | Uint8Array | string)[];
35+
}) {
3336
super();
34-
this.addTxs = input.addTxs;
35-
this.removeTxs = input.removeTxs;
37+
this.addTxs = input.addTxs.map((v) =>
38+
v instanceof Hash ? v : new Hash(v),
39+
);
40+
this.removeTxs = input.removeTxs.map((v) =>
41+
v instanceof Hash ? v : new Hash(v),
42+
);
3643
}
3744

3845
toXdrObject(): FreezeBypassTxsDeltaWire {

src/xdr/generated/freeze-bypass-txs.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ export class FreezeBypassTxs extends XdrValue {
2525
},
2626
);
2727

28-
constructor(input: { txHashes: Hash[] }) {
28+
constructor(input: { txHashes: (Hash | Uint8Array | string)[] }) {
2929
super();
30-
this.txHashes = input.txHashes;
30+
this.txHashes = input.txHashes.map((v) =>
31+
v instanceof Hash ? v : new Hash(v),
32+
);
3133
}
3234

3335
toXdrObject(): FreezeBypassTxsWire {

src/xdr/generated/frozen-ledger-keys-delta.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,16 @@ export class FrozenLedgerKeysDelta extends XdrValue {
3333
);
3434

3535
constructor(input: {
36-
keysToFreeze: EncodedLedgerKey[];
37-
keysToUnfreeze: EncodedLedgerKey[];
36+
keysToFreeze: (EncodedLedgerKey | Uint8Array | string)[];
37+
keysToUnfreeze: (EncodedLedgerKey | Uint8Array | string)[];
3838
}) {
3939
super();
40-
this.keysToFreeze = input.keysToFreeze;
41-
this.keysToUnfreeze = input.keysToUnfreeze;
40+
this.keysToFreeze = input.keysToFreeze.map((v) =>
41+
v instanceof EncodedLedgerKey ? v : new EncodedLedgerKey(v),
42+
);
43+
this.keysToUnfreeze = input.keysToUnfreeze.map((v) =>
44+
v instanceof EncodedLedgerKey ? v : new EncodedLedgerKey(v),
45+
);
4246
}
4347

4448
toXdrObject(): FrozenLedgerKeysDeltaWire {

src/xdr/generated/frozen-ledger-keys.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ export class FrozenLedgerKeys extends XdrValue {
2828
},
2929
);
3030

31-
constructor(input: { keys: EncodedLedgerKey[] }) {
31+
constructor(input: { keys: (EncodedLedgerKey | Uint8Array | string)[] }) {
3232
super();
33-
this.keys = input.keys;
33+
this.keys = input.keys.map((v) =>
34+
v instanceof EncodedLedgerKey ? v : new EncodedLedgerKey(v),
35+
);
3436
}
3537

3638
toXdrObject(): FrozenLedgerKeysWire {

0 commit comments

Comments
 (0)