Skip to content

Commit

Permalink
Use @mysten/sui package
Browse files Browse the repository at this point in the history
  • Loading branch information
ronanyeah committed Aug 7, 2024
1 parent 70ede19 commit 36cd344
Show file tree
Hide file tree
Showing 66 changed files with 1,332 additions and 1,686 deletions.
502 changes: 67 additions & 435 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"build:worker": "esbuild src/worker.ts --bundle --outfile=public/worker.js"
},
"dependencies": {
"@mysten/bcs": "^0.11.1",
"@mysten/sui.js": "^0.54.1",
"@mysten/bcs": "^1.0.4",
"@mysten/sui": "^1.5.0",
"@noble/hashes": "^1.4.0",
"chalk": "^5.3.0",
"commander": "^12.0.0",
Expand Down
14 changes: 7 additions & 7 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ import { epochReset } from "../codegen/mineral/mine/functions";
import { Config, MINE } from "../codegen/mineral/mine/structs";
import { Miner } from "../codegen/mineral/miner/structs";

import { bcs } from "@mysten/sui.js/bcs";
import { decodeSuiPrivateKey } from "@mysten/sui.js/cryptography";
import { bcs } from "@mysten/sui/bcs";
import { decodeSuiPrivateKey } from "@mysten/sui/cryptography";
import {
SuiTransactionBlockResponse,
SuiClient,
getFullnodeUrl,
} from "@mysten/sui.js/client";
import { Ed25519Keypair } from "@mysten/sui.js/keypairs/ed25519";
} from "@mysten/sui/client";
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
import {
SUI_TYPE_ARG,
SUI_DECIMALS,
SUI_CLOCK_OBJECT_ID,
} from "@mysten/sui.js/utils";
import { TransactionBlock } from "@mysten/sui.js/transactions";
} from "@mysten/sui/utils";
import { Transaction } from "@mysten/sui/transactions";

import {
MineProgress,
Expand Down Expand Up @@ -376,7 +376,7 @@ async function execReset(
client: SuiClient,
wallet: Ed25519Keypair
): Promise<SuiTransactionBlockResponse> {
const txb = new TransactionBlock();
const txb = new Transaction();
epochReset(txb, {
config: constants.CONFIG,
buses: constants.BUSES.map((x) =>
Expand Down
36 changes: 16 additions & 20 deletions src/codegen/_dependencies/source/0x1/ascii/structs.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import * as reified from "../../../../_framework/reified";
import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified";
import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util";
import {bcs, fromB64} from "@mysten/bcs";
import {SuiClient, SuiParsedData} from "@mysten/sui.js/client";
import {PKG_V8} from "../index";
import {bcs} from "@mysten/sui/bcs";
import {SuiClient, SuiParsedData} from "@mysten/sui/client";
import {fromB64} from "@mysten/sui/utils";

/* ============================== Char =============================== */

export function isChar(type: string): boolean { type = compressSuiType(type); return type === "0x1::ascii::Char"; }
export function isChar(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::ascii::Char`; }

export interface CharFields { byte: ToField<"u8"> }

export type CharReified = Reified< Char, CharFields >;

export class Char implements StructClass { static readonly $typeName = "0x1::ascii::Char"; static readonly $numTypeParams = 0;
export class Char implements StructClass { static readonly $typeName = `${PKG_V8}::ascii::Char`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const;

readonly $typeName = Char.$typeName;

readonly $fullTypeName: "0x1::ascii::Char";

readonly $typeArgs: [];
readonly $typeName = Char.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::ascii::Char`; readonly $typeArgs: []; readonly $isPhantom = Char.$isPhantom;

readonly byte: ToField<"u8">

private constructor(typeArgs: [], fields: CharFields, ) { this.$fullTypeName = composeSuiType( Char.$typeName, ...typeArgs ) as "0x1::ascii::Char"; this.$typeArgs = typeArgs;
private constructor(typeArgs: [], fields: CharFields, ) { this.$fullTypeName = composeSuiType( Char.$typeName, ...typeArgs ) as `${typeof PKG_V8}::ascii::Char`; this.$typeArgs = typeArgs;

this.byte = fields.byte; }

static reified( ): CharReified { return { typeName: Char.$typeName, fullTypeName: composeSuiType( Char.$typeName, ...[] ) as "0x1::ascii::Char", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => Char.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Char.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Char.fromBcs( data, ), bcs: Char.bcs, fromJSONField: (field: any) => Char.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => Char.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Char.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Char.fetch( client, id, ), new: ( fields: CharFields, ) => { return new Char( [], fields ) }, kind: "StructClassReified", } }
static reified( ): CharReified { return { typeName: Char.$typeName, fullTypeName: composeSuiType( Char.$typeName, ...[] ) as `${typeof PKG_V8}::ascii::Char`, typeArgs: [ ] as [], isPhantom: Char.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => Char.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => Char.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => Char.fromBcs( data, ), bcs: Char.bcs, fromJSONField: (field: any) => Char.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => Char.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => Char.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => Char.fetch( client, id, ), new: ( fields: CharFields, ) => { return new Char( [], fields ) }, kind: "StructClassReified", } }

static get r() { return Char.reified() }

Expand Down Expand Up @@ -65,33 +63,30 @@ export class Char implements StructClass { static readonly $typeName = "0x1::asc
static fromSuiParsedData( content: SuiParsedData ): Char { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isChar(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a Char object`); } return Char.fromFieldsWithTypes( content ); }

static async fetch( client: SuiClient, id: string ): Promise<Char> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching Char object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isChar(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a Char object`); }

return Char.fromBcs( fromB64(res.data.bcs.bcsBytes) ); }

}

/* ============================== String =============================== */

export function isString(type: string): boolean { type = compressSuiType(type); return type === "0x1::ascii::String"; }
export function isString(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::ascii::String`; }

export interface StringFields { bytes: ToField<Vector<"u8">> }

export type StringReified = Reified< String, StringFields >;

export class String implements StructClass { static readonly $typeName = "0x1::ascii::String"; static readonly $numTypeParams = 0;
export class String implements StructClass { static readonly $typeName = `${PKG_V8}::ascii::String`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const;

readonly $typeName = String.$typeName;

readonly $fullTypeName: "0x1::ascii::String";

readonly $typeArgs: [];
readonly $typeName = String.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::ascii::String`; readonly $typeArgs: []; readonly $isPhantom = String.$isPhantom;

readonly bytes: ToField<Vector<"u8">>

private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as "0x1::ascii::String"; this.$typeArgs = typeArgs;
private constructor(typeArgs: [], fields: StringFields, ) { this.$fullTypeName = composeSuiType( String.$typeName, ...typeArgs ) as `${typeof PKG_V8}::ascii::String`; this.$typeArgs = typeArgs;

this.bytes = fields.bytes; }

static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as "0x1::ascii::String", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } }
static reified( ): StringReified { return { typeName: String.$typeName, fullTypeName: composeSuiType( String.$typeName, ...[] ) as `${typeof PKG_V8}::ascii::String`, typeArgs: [ ] as [], isPhantom: String.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => String.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => String.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => String.fromBcs( data, ), bcs: String.bcs, fromJSONField: (field: any) => String.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => String.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => String.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => String.fetch( client, id, ), new: ( fields: StringFields, ) => { return new String( [], fields ) }, kind: "StructClassReified", } }

static get r() { return String.reified() }

Expand Down Expand Up @@ -130,6 +125,7 @@ export class String implements StructClass { static readonly $typeName = "0x1::a
static fromSuiParsedData( content: SuiParsedData ): String { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isString(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a String object`); } return String.fromFieldsWithTypes( content ); }

static async fetch( client: SuiClient, id: string ): Promise<String> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching String object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isString(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a String object`); }

return String.fromBcs( fromB64(res.data.bcs.bcsBytes) ); }

}
21 changes: 10 additions & 11 deletions src/codegen/_dependencies/source/0x1/bit-vector/structs.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
import * as reified from "../../../../_framework/reified";
import {PhantomReified, Reified, StructClass, ToField, ToTypeStr, Vector, decodeFromFields, decodeFromFieldsWithTypes, decodeFromJSONField, fieldToJSON, phantom} from "../../../../_framework/reified";
import {FieldsWithTypes, composeSuiType, compressSuiType} from "../../../../_framework/util";
import {bcs, fromB64} from "@mysten/bcs";
import {SuiClient, SuiParsedData} from "@mysten/sui.js/client";
import {PKG_V8} from "../index";
import {bcs} from "@mysten/sui/bcs";
import {SuiClient, SuiParsedData} from "@mysten/sui/client";
import {fromB64} from "@mysten/sui/utils";

/* ============================== BitVector =============================== */

export function isBitVector(type: string): boolean { type = compressSuiType(type); return type === "0x1::bit_vector::BitVector"; }
export function isBitVector(type: string): boolean { type = compressSuiType(type); return type === `${PKG_V8}::bit_vector::BitVector`; }

export interface BitVectorFields { length: ToField<"u64">; bitField: ToField<Vector<"bool">> }

export type BitVectorReified = Reified< BitVector, BitVectorFields >;

export class BitVector implements StructClass { static readonly $typeName = "0x1::bit_vector::BitVector"; static readonly $numTypeParams = 0;
export class BitVector implements StructClass { static readonly $typeName = `${PKG_V8}::bit_vector::BitVector`; static readonly $numTypeParams = 0; static readonly $isPhantom = [] as const;

readonly $typeName = BitVector.$typeName;

readonly $fullTypeName: "0x1::bit_vector::BitVector";

readonly $typeArgs: [];
readonly $typeName = BitVector.$typeName; readonly $fullTypeName: `${typeof PKG_V8}::bit_vector::BitVector`; readonly $typeArgs: []; readonly $isPhantom = BitVector.$isPhantom;

readonly length: ToField<"u64">; readonly bitField: ToField<Vector<"bool">>

private constructor(typeArgs: [], fields: BitVectorFields, ) { this.$fullTypeName = composeSuiType( BitVector.$typeName, ...typeArgs ) as "0x1::bit_vector::BitVector"; this.$typeArgs = typeArgs;
private constructor(typeArgs: [], fields: BitVectorFields, ) { this.$fullTypeName = composeSuiType( BitVector.$typeName, ...typeArgs ) as `${typeof PKG_V8}::bit_vector::BitVector`; this.$typeArgs = typeArgs;

this.length = fields.length;; this.bitField = fields.bitField; }

static reified( ): BitVectorReified { return { typeName: BitVector.$typeName, fullTypeName: composeSuiType( BitVector.$typeName, ...[] ) as "0x1::bit_vector::BitVector", typeArgs: [ ] as [], reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => BitVector.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BitVector.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BitVector.fromBcs( data, ), bcs: BitVector.bcs, fromJSONField: (field: any) => BitVector.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => BitVector.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BitVector.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BitVector.fetch( client, id, ), new: ( fields: BitVectorFields, ) => { return new BitVector( [], fields ) }, kind: "StructClassReified", } }
static reified( ): BitVectorReified { return { typeName: BitVector.$typeName, fullTypeName: composeSuiType( BitVector.$typeName, ...[] ) as `${typeof PKG_V8}::bit_vector::BitVector`, typeArgs: [ ] as [], isPhantom: BitVector.$isPhantom, reifiedTypeArgs: [], fromFields: (fields: Record<string, any>) => BitVector.fromFields( fields, ), fromFieldsWithTypes: (item: FieldsWithTypes) => BitVector.fromFieldsWithTypes( item, ), fromBcs: (data: Uint8Array) => BitVector.fromBcs( data, ), bcs: BitVector.bcs, fromJSONField: (field: any) => BitVector.fromJSONField( field, ), fromJSON: (json: Record<string, any>) => BitVector.fromJSON( json, ), fromSuiParsedData: (content: SuiParsedData) => BitVector.fromSuiParsedData( content, ), fetch: async (client: SuiClient, id: string) => BitVector.fetch( client, id, ), new: ( fields: BitVectorFields, ) => { return new BitVector( [], fields ) }, kind: "StructClassReified", } }

static get r() { return BitVector.reified() }

Expand Down Expand Up @@ -65,6 +63,7 @@ export class BitVector implements StructClass { static readonly $typeName = "0x1
static fromSuiParsedData( content: SuiParsedData ): BitVector { if (content.dataType !== "moveObject") { throw new Error("not an object"); } if (!isBitVector(content.type)) { throw new Error(`object at ${(content.fields as any).id} is not a BitVector object`); } return BitVector.fromFieldsWithTypes( content ); }

static async fetch( client: SuiClient, id: string ): Promise<BitVector> { const res = await client.getObject({ id, options: { showBcs: true, }, }); if (res.error) { throw new Error(`error fetching BitVector object at id ${id}: ${res.error.code}`); } if (res.data?.bcs?.dataType !== "moveObject" || !isBitVector(res.data.bcs.type)) { throw new Error(`object at id ${id} is not a BitVector object`); }

return BitVector.fromBcs( fromB64(res.data.bcs.bcsBytes) ); }

}
Loading

0 comments on commit 36cd344

Please sign in to comment.