Skip to content

Commit

Permalink
CU-86dth9jvx - Fix NeonInvoker's getNetworkFee to work with Neo-go an…
Browse files Browse the repository at this point in the history
…d new Neo versions
  • Loading branch information
luc10921 committed May 21, 2024
1 parent 02f7a4b commit 2965926
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
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

0 comments on commit 2965926

Please sign in to comment.