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

Support Chained Transactions #427

Merged
merged 15 commits into from
Oct 9, 2024
Merged

Support Chained Transactions #427

merged 15 commits into from
Oct 9, 2024

Conversation

h0ngcha0
Copy link
Member

@h0ngcha0 h0ngcha0 commented Oct 3, 2024

The chained transaction might be signed by multiple signers, so the interface currently looks like this. Please let me know if we can improve it:

// Transfer fund from group 1 to group 2
const transferTxParams: SignTransferChainedTxParams = {
      signerAddress: signer1.address,
      destinations: [{ address: signer2.address, attoAlphAmount: 10n * ONE_ALPH }],
      type: 'Transfer',
      publicKey: signer1.publicKey
}

// Interact with dApp in group 2
const depositTxParams = await Deposit.script.txParamsForExecution(signer2, {
      initialFields: { c: transactInstance.contractId },
      attoAlphAmount: ONE_ALPH
})

// Build chained txs
const [transferResult, depositResult] = await TransactionBuilder.from(nodeProvider).buildChainedTx([transferTxParams, depositTxParams])

// Sign and submit both txs
await signer1.signAndSubmitUnsignedTx({ unsignedTx: transferResult.unsignedTx, signerAddress: signer1.address })
await signer2.signAndSubmitUnsignedTx({ unsignedTx: depositResult.unsignedTx, signerAddress: signer2.address })

docker/docker-compose.yml Outdated Show resolved Hide resolved
@h0ngcha0 h0ngcha0 requested review from polarker and pragmaxim October 3, 2024 21:05
packages/web3/src/signer/signer.ts Outdated Show resolved Hide resolved
packages/web3/src/contract/contract.ts Outdated Show resolved Hide resolved
Comment on lines 97 to 103
const rootWallet = new PrivateKeyWallet({ privateKey: testPrivateKey })
const wallet = PrivateKeyWallet.Random(group)
const destinations = [{ address: wallet.address, attoAlphAmount: alphAmount }]
await rootWallet.signAndSubmitTransferTx({ signerAddress: testAddress, destinations })
if (alphAmount > 0n) {
const destinations = [{ address: wallet.address, attoAlphAmount: alphAmount }]
await rootWallet.signAndSubmitTransferTx({ signerAddress: testAddress, destinations })
}
return wallet
Copy link

@pragmaxim pragmaxim Oct 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot make sense of it as a newcomer, we sign the transfer with rootWallet and return PrivateKeyWallet.Random(group) which does not seem to hold any important information 🤔 How can we later use it to sign transactions? As we do signer1.publicKey / signer1.address

SOLVED: Sorry I understand now, it is a generator

if (alphAmount > 0n) {
const destinations = [{ address: wallet.address, attoAlphAmount: alphAmount }]
await rootWallet.signAndSubmitTransferTx({ signerAddress: testAddress, destinations })
}
return wallet
} catch (_) {
throw new Error('Failed to get signer, please restart the devnet')
Copy link

@pragmaxim pragmaxim Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please print the error cause it reveals the reason of failure :

  } catch (error) {
    throw new Error(`Failed to get signer, please restart the devnet due to : ${error}`)
  }

@polarker
Copy link
Member

polarker commented Oct 9, 2024

@Lbqds Please give a final review on this new feature, thanks!

Copy link
Member

@Lbqds Lbqds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@polarker polarker merged commit 60b5b3d into master Oct 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants