Skip to content

Commit

Permalink
Feature/client update args input (#115)
Browse files Browse the repository at this point in the history
* feat(client): upgrade client tx and query input args

* feat(client): upgrade client tx and query input args

* feat(create-dubhe): update sui client build

* feat(client): upgrade client tx and query input args

* feat(create-dubhe): upgrade create-dubhe version
  • Loading branch information
vladilen11 authored Dec 11, 2024
1 parent 338dcf9 commit 87eb8f7
Show file tree
Hide file tree
Showing 36 changed files with 377 additions and 225 deletions.
2 changes: 1 addition & 1 deletion packages/aptos-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xobelisk/aptos-client",
"version": "0.0.14",
"version": "0.0.16",
"description": "Tookit for interacting with move eps framework",
"keywords": [
"aptos",
Expand Down
30 changes: 19 additions & 11 deletions packages/aptos-client/scripts/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,40 @@ async function init() {

console.log('======= query other user message ========');

let message = await dubhe.query.message.get_message([
'0x35cc4910b9934ceacf0bbb014e3a823f9dee5b8725110360729b500ee81a2d3a',
]);
let message = await dubhe.query.message.get_message({
params: [
'0x35cc4910b9934ceacf0bbb014e3a823f9dee5b8725110360729b500ee81a2d3a',
],
});
console.log(message);

console.log('======= set our message ========');
const res1 = (await dubhe.tx.message.set_message(dubhe.getAddress(), [
'first set',
])) as PendingTransactionResponse;
const res1 = (await dubhe.tx.message.set_message({
sender: dubhe.getAddress(),
params: ['first set'],
})) as PendingTransactionResponse;
console.log(res1.hash);
await delay(1000);

console.log('======= query our message ========');
let myMessage = await dubhe.query.message.get_message([myAddr]);
let myMessage = await dubhe.query.message.get_message({
params: [myAddr],
});
console.log(myMessage);

console.log('======= set our message again ========');

const res2 = (await dubhe.tx.message.set_message(dubhe.getAddress(), [
'hello world',
])) as PendingTransactionResponse;
const res2 = (await dubhe.tx.message.set_message({
sender: dubhe.getAddress(),
params: ['hello world'],
})) as PendingTransactionResponse;
console.log(res2.hash);
await delay(1000);

console.log('======= query our message ========');
let mySecondMessage = await dubhe.query.message.get_message([myAddr]);
let mySecondMessage = await dubhe.query.message.get_message({
params: [myAddr],
});
console.log(mySecondMessage);

let faucetRes = await dubhe.requestFaucet(network);
Expand Down
36 changes: 23 additions & 13 deletions packages/aptos-client/src/dubhe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,15 @@ function createQuery(
): ContractQuery {
return withMeta(
meta,
async (
async ({
params,
typeArguments,
}: {
params?: Array<
EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes
>,
typeArguments?: Array<TypeArgument>
): Promise<MoveValue[]> => {
>;
typeArguments?: Array<TypeArgument>;
} = {}): Promise<MoveValue[]> => {
const result = await fn(params, typeArguments);
return result;
}
Expand All @@ -93,14 +96,19 @@ function createTx(
): ContractTx {
return withMeta(
meta,
async (
sender?: AccountAddressInput,
async ({
sender,
params,
typeArguments,
isRaw,
}: {
sender?: AccountAddressInput;
params?: Array<
EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes
>,
typeArguments?: Array<TypeArgument>,
isRaw?: boolean
): Promise<
>;
typeArguments?: Array<TypeArgument>;
isRaw?: boolean;
} = {}): Promise<
PendingTransactionResponse | InputGenerateTransactionPayloadData
> => {
const result = await fn(sender, params, typeArguments, isRaw);
Expand Down Expand Up @@ -184,7 +192,8 @@ export class Dubhe {
if (isUndefined(this.#query[moduleName][value.name])) {
this.#query[moduleName][value.name] = createQuery(
meta,
(p, type_p) => this.#read(meta, p, type_p)
(params, typeArguments) =>
this.#read(meta, params, typeArguments)
);
}
}
Expand All @@ -196,7 +205,8 @@ export class Dubhe {
if (isUndefined(this.#tx[moduleName][value.name])) {
this.#tx[moduleName][value.name] = createTx(
meta,
(s, p, type_p, isRaw) => this.#exec(meta, s, p, type_p, isRaw)
(sender, params, typeArguments, isRaw) =>
this.#exec(meta, sender, params, typeArguments, isRaw)
);
}
}
Expand Down Expand Up @@ -348,7 +358,7 @@ export class Dubhe {
}
if (coinType === undefined) {
coinType = '0x1::aptos_coin::AptosCoin';
}
} // tx.xx.xx(undef, undef, true)

const resource = await this.aptosInteractor.getAccountResource(
accountAddress,
Expand Down
30 changes: 20 additions & 10 deletions packages/aptos-client/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,33 @@ export interface MessageMeta {
}

export interface ContractQuery extends MessageMeta {
(
(): Promise<MoveValue[]>;
({
params,
typeArguments,
}: {
params?: Array<
EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes
>,
typeArguments?: Array<TypeArgument>
): Promise<MoveValue[]>;
>;
typeArguments?: Array<TypeArgument>;
}): Promise<MoveValue[]>;
}

export interface ContractTx extends MessageMeta {
(
sender?: AccountAddressInput,
(): Promise<PendingTransactionResponse | InputGenerateTransactionPayloadData>;
({
sender,
params,
typeArguments,
isRaw,
}: {
sender?: AccountAddressInput;
params?: Array<
EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes
>,
typeArguments?: Array<TypeArgument>,
isRaw?: boolean
): Promise<PendingTransactionResponse | InputGenerateTransactionPayloadData>;
>;
typeArguments?: Array<TypeArgument>;
isRaw?: boolean;
}): Promise<PendingTransactionResponse | InputGenerateTransactionPayloadData>;
}

export type MapMessageTx = Record<string, ContractTx>;
Expand Down
2 changes: 1 addition & 1 deletion packages/create-dubhe/cocos-lib-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"author": "[email protected]",
"license": "ISC",
"dependencies": {
"@0xobelisk/sui-client": "v0.5.28",
"@0xobelisk/sui-client": "v0.5.30",
"@0xobelisk/aptos-client": "^0.0.13",
"browser-resolve": "^2.0.0",
"browser-sync": "^2.29.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/create-dubhe/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-dubhe",
"version": "0.0.11",
"version": "0.0.12",
"type": "module",
"license": "MIT",
"author": "[email protected]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@0xobelisk/aptos-common": "^0.0.7",
"@0xobelisk/aptos-client": "^0.0.14",
"@0xobelisk/aptos-client": "^0.0.16",
"@0xobelisk/aptos-cli": "^0.0.12",
"clsx": "^1.2.1",
"dotenv": "^16.4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"prod:testnet": "pnpm config:store testnet && pnpm next"
},
"dependencies": {
"@0xobelisk/initia-client": "^0.0.3",
"@0xobelisk/initia-client": "^0.0.5",
"@0xobelisk/initia-cli": "^0.0.3",
"@0xobelisk/sui-common": "^0.5.21",
"clsx": "^1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@0xobelisk/aptos-common": "^0.0.7",
"@0xobelisk/aptos-client": "^0.0.14",
"@0xobelisk/aptos-client": "^0.0.16",
"@0xobelisk/aptos-cli": "^0.0.12",
"clsx": "^1.2.1",
"dotenv": "^16.4.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"prod:testnet": "pnpm config:store testnet && pnpm next"
},
"dependencies": {
"@0xobelisk/rooch-client": "^0.0.3",
"@0xobelisk/rooch-client": "^0.0.5",
"@0xobelisk/rooch-cli": "^0.0.3",
"@0xobelisk/sui-common": "^0.5.21",
"clsx": "^1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ const Home = () => {
});

const tx = new Transaction();
const response = await dubhe.tx.counter.increase(tx);
const response = await dubhe.tx.counter.increase({
tx,
});
console.log(response.execution_info.tx_hash, response.execution_info.status.type);
if (response.execution_info.status.type == 'executed') {
setTimeout(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@0xobelisk/sui-cli": "^0.5.34",
"@0xobelisk/sui-client": "^0.5.28",
"@0xobelisk/sui-client": "^0.5.30",
"@0xobelisk/sui-common": "^0.5.23",
"@mysten/sui": "1.7.0",
"clsx": "^1.2.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const Home = () => {
metadata: metadata,
});
const tx = new Transaction();
const query_value = (await dubhe.query.counter_schema.get_value(tx, [
tx.object(Counter_Object_Id),
])) as DevInspectResults;
const query_value = (await dubhe.query.counter_schema.get_value({
tx,
params: [tx.object(Counter_Object_Id)],
})) as DevInspectResults;
console.log('Counter value:', dubhe.view(query_value)[0]);
setValue(dubhe.view(query_value)[0]);
};
Expand All @@ -58,7 +59,11 @@ const Home = () => {
secretKey: PRIVATEKEY,
});
const tx = new Transaction();
(await dubhe.tx.counter_system.inc(tx, [tx.object(Counter_Object_Id)], undefined, true)) as TransactionResult;
(await dubhe.tx.counter_system.inc({
tx,
params: [tx.object(Counter_Object_Id)],
isRaw: true,
})) as TransactionResult;
const response = await dubhe.signAndSendTxn(tx);
if (response.effects.status.status == 'success') {
setTimeout(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4590,13 +4590,23 @@ function withMeta(meta, creator) {
return creator;
}
function createQuery(meta, fn) {
return withMeta(meta, async (tx, params, typeArguments, isRaw) => {
return withMeta(meta, async ({
tx,
params,
typeArguments,
isRaw
}) => {
const result = await fn(tx, params, typeArguments, isRaw);
return result;
});
}
function createTx(meta, fn) {
return withMeta(meta, async (tx, params, typeArguments, isRaw) => {
return withMeta(meta, async ({
tx,
params,
typeArguments,
isRaw
}) => {
return await fn(tx, params, typeArguments, isRaw);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@0xobelisk/sui-cli": "^0.5.34",
"@0xobelisk/sui-client": "^0.5.28",
"@0xobelisk/sui-client": "^0.5.30",
"@0xobelisk/sui-common": "^0.5.23"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@0xobelisk/sui-cli": "^0.5.34",
"@0xobelisk/sui-client": "^0.5.28",
"@0xobelisk/sui-client": "^0.5.30",
"@0xobelisk/sui-common": "^0.5.23",
"dotenv": "^16.4.5",
"chalk": "^4.1.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@0xobelisk/sui-cli": "^0.5.34",
"@0xobelisk/sui-client": "^0.5.28",
"@0xobelisk/sui-client": "^0.5.30",
"@0xobelisk/sui-common": "^0.5.23",
"@mysten/dapp-kit": "0.14.9",
"@mysten/sui": "1.7.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ const Home: React.FC = () => {
metadata: metadata,
});
const tx = new Transaction();
const queryValue = (await dubhe.query.counter_schema.get_value(tx, [
tx.object(Counter_Object_Id),
])) as DevInspectResults;
const queryValue = (await dubhe.query.counter_schema.get_value({
tx,
params: [tx.object(Counter_Object_Id)],
})) as DevInspectResults;
console.log('Counter value:', dubhe.view(queryValue)[0]);
setValue(dubhe.view(queryValue)[0]);
} catch (error) {
Expand Down Expand Up @@ -82,7 +83,11 @@ const Home: React.FC = () => {
metadata: metadata,
});
const tx = new Transaction();
await dubhe.tx.counter_system.inc(tx, [tx.object(Counter_Object_Id)], undefined, true);
await dubhe.tx.counter_system.inc({
tx,
params: [tx.object(Counter_Object_Id)],
isRaw: true,
});
await signAndExecuteTransaction(
{
transaction: tx.serialize(),
Expand Down
2 changes: 1 addition & 1 deletion packages/initia-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@0xobelisk/initia-client",
"version": "0.0.3",
"version": "0.0.5",
"description": "Tookit for interacting with initia move framework",
"keywords": [
"initia",
Expand Down
7 changes: 4 additions & 3 deletions packages/initia-client/scripts/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ async function init() {
console.log(content);

console.log('======= write content value ========');
const res1 = await dubhe.tx.read_write.write(myHexAddr, [
bcs.string().serialize('reset new content!').toBase64(),
]);
const res1 = await dubhe.tx.read_write.write({
sender: myHexAddr,
params: [bcs.string().serialize('reset new content!').toBase64()],
});
console.log(res1);
await delay(6000);

Expand Down
Loading

0 comments on commit 87eb8f7

Please sign in to comment.