Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vladilen11 committed Sep 21, 2023
1 parent 97d8e9a commit b2575a2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
37 changes: 33 additions & 4 deletions packages/client/scripts/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<vector<u8>>', 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<u8>', data_bytes);
// console.log(data_bytes);
Expand Down
10 changes: 4 additions & 6 deletions packages/client/src/obelisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/codegen/utils/renderMove/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ export function renderSigletonEncodeFunc(): string {
`;
}

// todo: struct / bag
function renderBcsDecodeFunc(type: string) {
if (type === "address") {
return `bcs::peel_address(&mut data)`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down

0 comments on commit b2575a2

Please sign in to comment.