From 29659269c1217cf8f6b732a6a082a529b6400d66 Mon Sep 17 00:00:00 2001 From: luc10921 Date: Tue, 21 May 2024 14:10:26 -0300 Subject: [PATCH] CU-86dth9jvx - Fix NeonInvoker's getNetworkFee to work with Neo-go and new Neo versions --- .../neon-dappkit/CU-86dth9jvx_2024-05-20-15-42.json | 10 ++++++++++ packages/neon-dappkit/src/NeonInvoker.spec.ts | 3 +-- packages/neon-dappkit/src/NeonInvoker.ts | 13 +++++++------ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 common/changes/@cityofzion/neon-dappkit/CU-86dth9jvx_2024-05-20-15-42.json diff --git a/common/changes/@cityofzion/neon-dappkit/CU-86dth9jvx_2024-05-20-15-42.json b/common/changes/@cityofzion/neon-dappkit/CU-86dth9jvx_2024-05-20-15-42.json new file mode 100644 index 0000000..07f8e1e --- /dev/null +++ b/common/changes/@cityofzion/neon-dappkit/CU-86dth9jvx_2024-05-20-15-42.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@cityofzion/neon-dappkit", + "comment": "Use placeholder accounts when calculating networkfee", + "type": "patch" + } + ], + "packageName": "@cityofzion/neon-dappkit" +} \ No newline at end of file diff --git a/packages/neon-dappkit/src/NeonInvoker.spec.ts b/packages/neon-dappkit/src/NeonInvoker.spec.ts index 9ba2c4d..e6509ee 100644 --- a/packages/neon-dappkit/src/NeonInvoker.spec.ts +++ b/packages/neon-dappkit/src/NeonInvoker.spec.ts @@ -342,8 +342,7 @@ describe('NeonInvoker', function () { ], }), { - name: 'Error', - message: 'Invalid', + message: /^Inventory verification failed/, }, ) }) diff --git a/packages/neon-dappkit/src/NeonInvoker.ts b/packages/neon-dappkit/src/NeonInvoker.ts index 952b970..edfa83f 100644 --- a/packages/neon-dappkit/src/NeonInvoker.ts +++ b/packages/neon-dappkit/src/NeonInvoker.ts @@ -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)