diff --git a/packages/client/scripts/init.ts b/packages/client/scripts/init.ts index e03a3ce6..506d9179 100644 --- a/packages/client/scripts/init.ts +++ b/packages/client/scripts/init.ts @@ -58,18 +58,47 @@ async function init() { // let data1 = await obelisk.getComponent("0x36cbd7d72444757040b496e7380af38c873e3ce4a88a30a0800ed7d3a24b3929", hexdata) let data1 = await obelisk.getComponentByName( '0x8ca551499f40b18ee42e9537ce1e22c2f40120c014ee13c77ab8162b546c3575', - 'withinfinity', - 'counter' + 'counter', + 'withinfinity' ); - // console.log(JSON.stringify(data1.data?.content )); + console.log(JSON.stringify(data1.data?.content)); let content = data1.data!.content as data; let res = content.fields!.value!.fields.data; const bcs = new BCS(getSuiMoveConfig()); - + console.log(res); const byteArray = new Uint8Array(res); const data2 = bcs.de('u64', byteArray); console.log(data2); + const tx = new TransactionBlock(); + let params = [] as SuiTxArgument[]; + // let res2 = await obelisk.query.pet_system.get_pet_basic_info(tx, params) as DevInspectResults; + const resq = (await obelisk.query.counter_comp.field_types( + tx, + params + )) as DevInspectResults; + // console.log(JSON.stringify(resq.results![0].returnValues!)); + let returnData = resq.results![0].returnValues!; + + console.log(returnData); + let databytes = new Uint8Array(returnData[0][0]); + const data3 = bcs.de('vector>', databytes)[0]; + const asciiString: string = String.fromCharCode(...data3); + + console.log(data3); + console.log(asciiString); + + // const tx = new TransactionBlock(); + // let params = [tx.pure(res) as SuiTxArgument] as SuiTxArgument[]; + // // let res2 = await obelisk.query.pet_system.get_pet_basic_info(tx, params) as DevInspectResults; + // const resq = (await obelisk.query.counter_comp.decode( + // tx, + // params + // )) as DevInspectResults; + // console.log(JSON.stringify(resq.results![0].returnValues!)); + // let returnData = resq.results![0].returnValues!; + // const data3 = bcs.de(returnData[0][1], byteArray); + // // Same with deserialization // let data_restored = bcs.de('vector', data_bytes); // console.log(data_bytes); diff --git a/packages/client/src/obelisk.ts b/packages/client/src/obelisk.ts index 80a0a54b..d830381a 100644 --- a/packages/client/src/obelisk.ts +++ b/packages/client/src/obelisk.ts @@ -456,16 +456,14 @@ export class Obelisk { async getComponentByName( worldId: string, - packageName: string, - componentName: string + componentName: string, + packageName: string ) { - const componentNameId = `${capitalizeFirstLetter( - packageName - )} ${capitalizeFirstLetter(componentName)} Comp`; + const componentNameId = `${capitalizeFirstLetter(componentName)} Comp`; const componentId = keccak256(componentNameId); return await this.getComponent(worldId, componentId); } - + async getComponent(worldId: string, componentId: Buffer) { const componentIdValue: number[] = Array.from(componentId); const parentId = (await this.suiInteractor.getObject(worldId)).objectFields diff --git a/packages/common/src/codegen/utils/renderMove/common.ts b/packages/common/src/codegen/utils/renderMove/common.ts index 061c125b..e969f3fd 100644 --- a/packages/common/src/codegen/utils/renderMove/common.ts +++ b/packages/common/src/codegen/utils/renderMove/common.ts @@ -373,6 +373,7 @@ export function renderSigletonEncodeFunc(): string { `; } +// todo: struct / bag function renderBcsDecodeFunc(type: string) { if (type === "address") { return `bcs::peel_address(&mut data)`; diff --git a/packages/common/src/codegen/utils/renderMove/generateComponent.ts b/packages/common/src/codegen/utils/renderMove/generateComponent.ts index 4feaf597..7179cb18 100644 --- a/packages/common/src/codegen/utils/renderMove/generateComponent.ts +++ b/packages/common/src/codegen/utils/renderMove/generateComponent.ts @@ -36,9 +36,7 @@ export function generateComponent(config: ObeliskConfig, srcPrefix: string) { ${getFriendSystem(config.projectName, config.systems)} \tpublic fun id() : address { -\t\tentity_key::from_bytes(b"${capitalizeFirstLetter( - config.projectName - )} ${capitalizeFirstLetter(componentName)} Comp") +\t\tentity_key::from_bytes(b"${capitalizeFirstLetter(componentName)} Comp") \t} ${renderStruct(value)} ${renderRegisterFunc()}