Skip to content

Commit

Permalink
Merge pull request #202 from thepower/fix/clI_container_upload_fix
Browse files Browse the repository at this point in the history
fix cli containers actions examples, fix create provider, fix scSet
  • Loading branch information
jackkru69 authored Dec 18, 2024
2 parents c1405e3 + 5671591 commit 6f698ba
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/good-falcons-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@thepowereco/tssdk': patch
'@thepowereco/cli': patch
---

fix cli containers actions examples, fix create provider, fix scSet
9 changes: 9 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"mode": "pre",
"tag": "canary",
"initialVersions": {
"@thepowereco/cli": "1.12.15",
"@thepowereco/tssdk": "2.2.12"
},
"changesets": []
}
12 changes: 6 additions & 6 deletions packages/cli/src/commands/container/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
18 changes: 9 additions & 9 deletions packages/cli/src/commands/container/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/commands/contract/deploy.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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(
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/src/commands/storage/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 28 additions & 7 deletions packages/tssdk/src/libs/evm-api/evmCore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type Abi } from 'abitype'
import {
encodeFunctionData,
decodeFunctionResult,
type EncodeFunctionDataParameters,
hexToBytes,
type DecodeFunctionResultReturnType
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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<DecodeFunctionResultReturnType<TAbi, TFunctionName, TArgs>>
const typedResponse = response as TxResponse<`0x${string}`>

const retval = typedResponse?.retval

if (retval) {
const decodedRetval = decodeFunctionResult({
abi,
data: retval,
functionName
}) as DecodeFunctionResultReturnType<TAbi, TFunctionName, TArgs>

return {
...typedResponse,
retval: decodedRetval
}
}
return typedResponse
}
}

0 comments on commit 6f698ba

Please sign in to comment.