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

CU-86dth9jvx - Fix NeonInvoker's getNetworkFee to work with Neo-go an… #38

Merged
merged 1 commit into from
May 21, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/neon-dappkit",
"comment": "Use placeholder accounts when calculating networkfee",
"type": "patch"
}
],
"packageName": "@cityofzion/neon-dappkit"
}
3 changes: 1 addition & 2 deletions packages/neon-dappkit/src/NeonInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ describe('NeonInvoker', function () {
],
}),
{
name: 'Error',
message: 'Invalid',
message: /^Inventory verification failed/,
},
)
})
Expand Down
13 changes: 7 additions & 6 deletions packages/neon-dappkit/src/NeonInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,20 +294,21 @@ export class NeonInvoker implements Neo3Invoker {
}

const txClone = new tx.Transaction(transaction)
// Add one witness for each signer, using the first account as placeholder if there is no account for the respective signer

// Add one witness for each signer and use placeholder accounts to calculate the network fee.
// This is needed to calculate the network fee, since the signer is considered to calculate the fee and we need
// the same number of witnesses as signers, otherwise the fee calculation will fail
txClone.signers.forEach((signer) => {
const account = accountArr.find((account) => account.scriptHash === signer.account.toString()) ?? accountArr[0]
if (!account) throw new Error('You need to provide at least one account to calculate the network fee.')
for (let i = 0; i < txClone.signers.length; i++) {
const placeholderAccount = new wallet.Account()
txClone.signers[i].account = u.HexString.fromHex(placeholderAccount.scriptHash)

txClone.addWitness(
new tx.Witness({
invocationScript: '',
verificationScript: wallet.getVerificationScriptFromPublicKey(account.publicKey),
verificationScript: wallet.getVerificationScriptFromPublicKey(placeholderAccount.publicKey),
}),
)
})
}

const networkFee = await api.smartCalculateNetworkFee(txClone, rpcClient)

Expand Down
Loading