Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added seq to other set methods #134

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading