Skip to content

Commit

Permalink
Merge pull request #134 from thepower/fix/fix-seq
Browse files Browse the repository at this point in the history
fix: added seq to other set methods
  • Loading branch information
jackkru69 authored Jun 24, 2024
2 parents 7f5d511 + de00573 commit 3b14471
Show file tree
Hide file tree
Showing 6 changed files with 236 additions and 128 deletions.
4 changes: 4 additions & 0 deletions packages/cli/src/commands/contract/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ export default class ContractDeploy extends Command {
// Format initialization parameters
const formattedInitParams = initParams.map((param) => (AddressApi.isTextAddressValid(param) ? AddressApi.textAddressToEvmAddress(param) : param));

const sequence = await networkApi.getWalletSequence(importedWallet.address);
const newSequence = sequence + 1;

// Compose the deployment transaction
const deployTX = TransactionsApi.composeDeployTX({
abi,
address: importedWallet.address,
code,
seq: newSequence,
feeSettings: networkApi.feeSettings,
gasSettings: networkApi.gasSettings,
gasToken,
Expand Down
26 changes: 16 additions & 10 deletions packages/tssdk/src/libs/evm-api/evm-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,23 @@ export class EvmApi {
const data = hexToBytes(encodedFunction);
const dataBuffer = Buffer.from(data);

const sequence = await this.network.getWalletSequence(this.scAddress);
const newSequence = sequence + 1;

const tx = await TransactionsApi.composeSCMethodCallTX(
key.address,
this.scAddress,
['0x0', [dataBuffer]],
'',
0,
key.wif,
'SK',
amount,
this.network.feeSettings,
this.network.gasSettings,
{
address: key.address,
sc: this.scAddress,
toCall: ['0x0', [dataBuffer]],
gasToken: '',
gasValue: 0,
wif: key.wif,
amountToken: 'SK',
amountValue: amount,
seq: newSequence,
feeSettings: this.network.feeSettings,
gasSettings: this.network.gasSettings,
},
);

return this.network.sendTxAndWaitForResponse(tx);
Expand Down
51 changes: 30 additions & 21 deletions packages/tssdk/src/libs/evm-api/evmCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,40 @@ export class EvmContract {
const data = hexToBytes(encodedFunction);
const dataBuffer = Buffer.from(data);

const sequence = await this.evm.network.getWalletSequence(key.address);
const newSequence = sequence + 1;

const tx = sponsor === '' ?
await TransactionsApi.composeSCMethodCallTX(
key.address,
this.address,
['0x0', [dataBuffer]],
'',
0,
key.wif,
'SK',
amount,
this.evm.network.feeSettings,
this.evm.network.gasSettings,
{
address: key.address,
sc: this.address,
toCall: ['0x0', [dataBuffer]],
gasToken: '',
gasValue: 0,
wif: key.wif,
amountToken: 'SK',
amountValue: amount,
seq: newSequence,
feeSettings: this.evm.network.feeSettings,
gasSettings: this.evm.network.gasSettings,
},
) :
await TransactionsApi.composeSponsorSCMethodCallTX(
key.address,
this.address,
['0x0', [dataBuffer]],
'',
0,
key.wif,
'SK',
amount,
this.evm.network.feeSettings,
this.evm.network.gasSettings,
sponsor,
{
address: key.address,
sc: this.address,
toCall: ['0x0', [dataBuffer]],
gasToken: '',
gasValue: 0,
wif: key.wif,
amountToken: 'SK',
amountValue: amount,
seq: newSequence,
feeSettings: this.evm.network.feeSettings,
gasSettings: this.evm.network.gasSettings,
sponsor,
},
);

const res = await this.evm.network.sendTxAndWaitForResponse(tx);
Expand Down
15 changes: 11 additions & 4 deletions packages/tssdk/src/libs/lstore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,22 @@ const getLStore = async (address: string, path: string, key: string, network: Ne
const setLStore = async (account: AccountKey, patches: [string, string, string][], network: NetworkApi) => {
const addressChain = await network.getAddressChain(account.address);
const addressChainNumber = addressChain?.chain;

if (network.getChain() !== addressChainNumber) {
await network.changeChain(addressChainNumber);
}

const sequence = await network.getWalletSequence(account.address);
const newSequence = sequence + 1;

const tx = await TransactionsApi.composeStoreTX(
account.address,
patches,
account.wif,
network.feeSettings,
{
address: account.address,
patches,
wif: account.wif,
seq: newSequence,
feeSettings: network.feeSettings,
},
);
return tx;
};
Expand Down
Loading

0 comments on commit 3b14471

Please sign in to comment.