From 5671591eea56760473c9ce3712667ee756dbc4d0 Mon Sep 17 00:00:00 2001 From: jackkru69 Date: Wed, 18 Dec 2024 16:52:42 +0700 Subject: [PATCH] fix cli containers actions examples, fix create provider, fix scSet --- .changeset/good-falcons-lick.md | 6 ++++ .changeset/pre.json | 9 +++++ .../cli/src/commands/container/actions.ts | 12 +++---- packages/cli/src/commands/container/create.ts | 18 +++++----- packages/cli/src/commands/contract/deploy.ts | 8 +++-- packages/cli/src/commands/storage/upload.ts | 10 ------ packages/tssdk/src/libs/evm-api/evmCore.ts | 35 +++++++++++++++---- 7 files changed, 64 insertions(+), 34 deletions(-) create mode 100644 .changeset/good-falcons-lick.md create mode 100644 .changeset/pre.json diff --git a/.changeset/good-falcons-lick.md b/.changeset/good-falcons-lick.md new file mode 100644 index 00000000..32808bde --- /dev/null +++ b/.changeset/good-falcons-lick.md @@ -0,0 +1,6 @@ +--- +'@thepowereco/tssdk': patch +'@thepowereco/cli': patch +--- + +fix cli containers actions examples, fix create provider, fix scSet diff --git a/.changeset/pre.json b/.changeset/pre.json new file mode 100644 index 00000000..138e4272 --- /dev/null +++ b/.changeset/pre.json @@ -0,0 +1,9 @@ +{ + "mode": "pre", + "tag": "canary", + "initialVersions": { + "@thepowereco/cli": "1.12.15", + "@thepowereco/tssdk": "2.2.12" + }, + "changesets": [] +} diff --git a/packages/cli/src/commands/container/actions.ts b/packages/cli/src/commands/container/actions.ts index 62398e90..b16a6f0c 100644 --- a/packages/cli/src/commands/container/actions.ts +++ b/packages/cli/src/commands/container/actions.ts @@ -42,12 +42,12 @@ export default class ContainerActions extends BaseCommand { static override description = 'Perform various container actions' static override examples = [ - '<%= config.bin %> <%= command.id %> -m "container_start" -p 1 -f ./path/to/keyfile.pem -s mypassword', - '<%= config.bin %> <%= command.id %> -m "container_stop" -p 1 -f ./path/to/keyfile.pem -s mypassword', - '<%= config.bin %> <%= command.id %> -m "container_destroy" -p 1 -f ./path/to/keyfile.pem -s mypassword', - '<%= config.bin %> <%= command.id %> -m "container_handover" -p 1 -f ./path/to/keyfile.pem -s mypassword', - '<%= config.bin %> <%= command.id %> -m "container_getPort" -p "1 web 5000" -f ./path/to/keyfile.pem -s mypassword', - '<%= config.bin %> <%= command.id %> -m "container_getLogs" -p 1 -f ./path/to/keyfile.pem -s mypassword' + '<%= config.bin %> <%= command.id %> -m "container_start" -i 1 -p 1 -f ./path/to/keyfile.pem -s mypassword', + '<%= config.bin %> <%= command.id %> -m "container_stop" -i 1 -p 1 -f ./path/to/keyfile.pem -s mypassword', + '<%= config.bin %> <%= command.id %> -m "container_destroy" -i 1 -p 1 -f ./path/to/keyfile.pem -s mypassword', + '<%= config.bin %> <%= command.id %> -m "container_handover" -i 1 -p 1 -f ./path/to/keyfile.pem -s mypassword', + '<%= config.bin %> <%= command.id %> -m "container_getPort" -i 1 -p "1 web 5000" -f ./path/to/keyfile.pem -s mypassword', + '<%= config.bin %> <%= command.id %> -m "container_getLogs" -i 1 -p 1 -f ./path/to/keyfile.pem -s mypassword' ] static override flags = { diff --git a/packages/cli/src/commands/container/create.ts b/packages/cli/src/commands/container/create.ts index a469fa46..3ad83e8e 100644 --- a/packages/cli/src/commands/container/create.ts +++ b/packages/cli/src/commands/container/create.ts @@ -93,15 +93,6 @@ export default class ContainerCreate extends BaseCommand { const jwkPublicKey = crypto.createPublicKey(publicKeyPem).export({ format: 'jwk' }) const compactPublicKey = createCompactPublicKey(jwkPublicKey) - if (!containerKeyFilePath && compactPublicKey?.base64) { - this.savePrivateKey({ - privateKeyPem, - containerName, - compactPublicKeyBase64: compactPublicKey.base64, - containerPassword - }) - } - const mintResponse = await ordersContract.scSet( { abi: abis.order, @@ -117,6 +108,15 @@ export default class ContainerCreate extends BaseCommand { { key: importedWallet, sponsor: sponsorAddress } ) + if (!containerKeyFilePath && compactPublicKey?.base64) { + this.savePrivateKey({ + privateKeyPem, + containerName, + compactPublicKeyBase64: compactPublicKey.base64, + containerPassword + }) + } + ux.action.stop() if (mintResponse?.txId) { diff --git a/packages/cli/src/commands/contract/deploy.ts b/packages/cli/src/commands/contract/deploy.ts index 77705b0b..fc371c7d 100644 --- a/packages/cli/src/commands/contract/deploy.ts +++ b/packages/cli/src/commands/contract/deploy.ts @@ -1,5 +1,5 @@ import { Flags, ux } from '@oclif/core' -import { TransactionsApi } from '@thepowereco/tssdk' +import { AddressApi, TransactionsApi } from '@thepowereco/tssdk' import { readFileSync } from 'fs' import { color } from '@oclif/color' @@ -147,11 +147,15 @@ export default class ContractDeploy extends BaseCommand { ) // Send the prepared transaction - const result = (await networkApi.sendPreparedTX(deployTX)) as { txId?: string } + const result = (await networkApi.sendPreparedTX(deployTX)) as { txId?: string; res: string } ux.action.stop() if (result?.txId) { + if (result?.res) { + result.res = AddressApi.evmAddressToTextAddress(result.res) + } + this.log(colorize(result)) this.log( color.yellow( diff --git a/packages/cli/src/commands/storage/upload.ts b/packages/cli/src/commands/storage/upload.ts index 338b3880..7cc467e0 100644 --- a/packages/cli/src/commands/storage/upload.ts +++ b/packages/cli/src/commands/storage/upload.ts @@ -106,16 +106,6 @@ export default class StorageUpload extends Command { throw new Error('No wallet found.') } - /* - * Await storageSc.scSet( - * importedWallet, - * 'addTask', - * [projectId, manifestHash, expire, totalSize], - * 1, // TODO: Change to normal amount - * sponsorAddress, - * ); - */ - await storageSc.scSet( { abi: abis.storage, diff --git a/packages/tssdk/src/libs/evm-api/evmCore.ts b/packages/tssdk/src/libs/evm-api/evmCore.ts index 08a9bdcd..c4d24936 100755 --- a/packages/tssdk/src/libs/evm-api/evmCore.ts +++ b/packages/tssdk/src/libs/evm-api/evmCore.ts @@ -1,6 +1,7 @@ import { type Abi } from 'abitype' import { encodeFunctionData, + decodeFunctionResult, type EncodeFunctionDataParameters, hexToBytes, type DecodeFunctionResultReturnType @@ -60,11 +61,15 @@ export class EvmContract { { key, amount = 0n, - sponsor = '' + sponsor = '', + gasToken = '', + gasValue = 0n }: { key: AccountKey amount?: bigint sponsor?: string + gasToken?: string + gasValue?: bigint } ) { const { abi, functionName, args = [] } = parameters as EncodeFunctionDataParameters @@ -94,8 +99,8 @@ export class EvmContract { address: key.address, sc: this.address, toCall: ['0x0', [dataBuffer]], - gasToken: '', - gasValue: 0n, + gasToken, + gasValue, wif: key.wif, seq: newSequence, amountToken: 'SK', @@ -107,8 +112,8 @@ export class EvmContract { address: key.address, sc: this.address, toCall: ['0x0', [dataBuffer]], - gasToken: '', - gasValue: 0n, + gasToken, + gasValue, wif: key.wif, seq: newSequence, amountToken: 'SK', @@ -118,8 +123,24 @@ export class EvmContract { sponsor }) - const res = await this.network.sendTxAndWaitForResponse(tx) + const response = await this.network.sendTxAndWaitForResponse(tx) - return res as TxResponse> + const typedResponse = response as TxResponse<`0x${string}`> + + const retval = typedResponse?.retval + + if (retval) { + const decodedRetval = decodeFunctionResult({ + abi, + data: retval, + functionName + }) as DecodeFunctionResultReturnType + + return { + ...typedResponse, + retval: decodedRetval + } + } + return typedResponse } }