@0xobelisk/sui-client 0.5.30 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/dubhe.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import keccak256 from 'keccak256';
2
2
  import { getFullnodeUrl } from '@mysten/sui/client';
3
3
  import { Transaction, TransactionResult } from '@mysten/sui/transactions';
4
- import { BcsType, SerializedBcs } from '@mysten/bcs';
4
+ import { BcsType, fromHex, SerializedBcs, toHex } from '@mysten/bcs';
5
5
  import type { TransactionArgument } from '@mysten/sui/transactions';
6
6
  import type {
7
7
  SuiTransactionBlockResponse,
@@ -155,8 +155,8 @@ export class Dubhe {
155
155
  bcs.vector(
156
156
  bcs.bytes(32).transform({
157
157
  // To change the input type, you need to provide a type definition for the input
158
- input: (val: string) => fromHEX(val),
159
- output: (val) => toHEX(val),
158
+ input: (val: string) => fromHex(val),
159
+ output: (val) => toHex(val),
160
160
  })
161
161
  )
162
162
  ),
@@ -170,8 +170,8 @@ export class Dubhe {
170
170
  'vector<address>': bcs.vector(
171
171
  bcs.bytes(32).transform({
172
172
  // To change the input type, you need to provide a type definition for the input
173
- input: (val: string) => fromHEX(val),
174
- output: (val) => toHEX(val),
173
+ input: (val: string) => fromHex(val),
174
+ output: (val) => toHex(val),
175
175
  })
176
176
  ),
177
177
  'vector<u8>': bcs.vector(bcs.u8()),
@@ -185,8 +185,8 @@ export class Dubhe {
185
185
  bcs.vector(
186
186
  bcs.bytes(32).transform({
187
187
  // To change the input type, you need to provide a type definition for the input
188
- input: (val: string) => fromHEX(val),
189
- output: (val) => toHEX(val),
188
+ input: (val: string) => fromHex(val),
189
+ output: (val) => toHex(val),
190
190
  })
191
191
  )
192
192
  ),
@@ -197,6 +197,18 @@ export class Dubhe {
197
197
  'vector<vector<u128>>': bcs.vector(bcs.vector(bcs.u128())),
198
198
  'vector<vector<u256>>': bcs.vector(bcs.vector(bcs.u256())),
199
199
  'vector<vector<bool>>': bcs.vector(bcs.vector(bcs.bool())),
200
+ '0x2::coin::Coin<T>': bcs.struct('Coin', {
201
+ id: bcs.fixedArray(32, bcs.u8()).transform({
202
+ input: (id: string) => fromHex(id),
203
+ output: (id) => toHex(Uint8Array.from(id)),
204
+ }),
205
+ balance: bcs.struct('Balance', {
206
+ value: bcs.u64(),
207
+ }),
208
+ }),
209
+ '0x2::balance::Balance<T>': bcs.struct('Balance', {
210
+ value: bcs.u64(),
211
+ }),
200
212
  };
201
213
 
202
214
  /**
@@ -570,33 +582,47 @@ export class Dubhe {
570
582
  for (const res of resultList) {
571
583
  let baseValue = res[0];
572
584
  let baseType = res[1];
573
-
574
585
  const value = Uint8Array.from(baseValue);
575
586
 
576
- if (!this.#object[baseType]) {
577
- console.log(
578
- '\n\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mUnsupported Type\x1b[0m'
579
- );
580
- console.log('\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
581
- console.log(`\x1b[95m•\x1b[0m Type: \x1b[33m"${baseType}"\x1b[0m`);
582
- console.log('\x1b[95m\n✨ Available Types:\x1b[0m');
583
- Object.keys(this.#object).forEach((type) => {
584
- console.log(` \x1b[36m◆\x1b[0m ${type}`);
585
- });
586
- console.log('\n\x1b[34m💡 How to Add Custom Type:\x1b[0m');
587
- console.log(
588
- ` You can add custom type by extending the #object map in your code:`
589
- );
590
- console.log(
591
- ` \x1b[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {\n field1: bcs.string(),\n field2: bcs.u64(),\n // ... other fields\n });\x1b[0m`
592
- );
587
+ if (this.#object[baseType]) {
588
+ returnValues.push(this.#object[baseType].parse(value));
589
+ continue;
590
+ }
591
+
592
+ const genericMatch = baseType.match(/^([^<]+)<(.+)>$/);
593
+ if (genericMatch) {
594
+ const [_, genericBase, _genericParam] = genericMatch;
595
+ const genericKey = `${genericBase}<T>`;
596
+
597
+ if (this.#object[genericKey]) {
598
+ returnValues.push(this.#object[genericKey].parse(value));
599
+ continue;
600
+ }
601
+ }
602
+
603
+ console.log(
604
+ '\n\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mUnsupported Type\x1b[0m'
605
+ );
606
+ console.log('\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m');
607
+ console.log(`\x1b[95m•\x1b[0m Type: \x1b[33m"${baseType}"\x1b[0m`);
608
+ if (genericMatch) {
593
609
  console.log(
594
- '\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n'
610
+ `\x1b[95m•\x1b[0m Generic Base Type: \x1b[33m"${genericMatch[1]}<T>"\x1b[0m`
595
611
  );
596
- throw new Error(`Unsupported type: ${baseType}`);
597
612
  }
598
-
599
- returnValues.push(this.#object[baseType].parse(value));
613
+ console.log('\x1b[95m\n✨ Available Types:\x1b[0m');
614
+ Object.keys(this.#object).forEach((type) => {
615
+ console.log(` \x1b[36m◆\x1b[0m ${type}`);
616
+ });
617
+ console.log('\n\x1b[34m💡 How to Add Custom Type:\x1b[0m');
618
+ console.log(
619
+ ` You can add custom type by extending the #object map in your code:`
620
+ );
621
+ console.log(
622
+ ` \x1b[32mdubhe.object["${baseType}"] = bcs.struct("YourTypeName", {\n field1: bcs.string(),\n field2: bcs.u64(),\n // ... other fields\n });\x1b[0m`
623
+ );
624
+ console.log('\x1b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1b[0m\n');
625
+ throw new Error(`Unsupported type: ${baseType}`);
600
626
  }
601
627
  return returnValues;
602
628
  } else {