From ea1a93d99614f2439308844bb05a6c2957af2206 Mon Sep 17 00:00:00 2001 From: classicalliu Date: Tue, 22 Oct 2019 17:03:58 +0800 Subject: [PATCH] chore: notes for transaction size --- packages/neuron-wallet/src/services/cells.ts | 4 ++++ .../neuron-wallet/src/services/tx/transaction-generator.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 55cf820fc4..9f77284c2d 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -166,6 +166,10 @@ export default class CellsService { } public static everyInputFee = (feeRate: bigint): bigint => { + /* + * every input need 44 Bytes and extra 4 Bytes for offset + * every input need 1 witness signed by secp256k1, with 65 Bytes data, and serialized in 69 Bytes + */ const ratio = BigInt(1000) const base = BigInt(4 + 44 + 69) * feeRate const fee = base / ratio diff --git a/packages/neuron-wallet/src/services/tx/transaction-generator.ts b/packages/neuron-wallet/src/services/tx/transaction-generator.ts index 3d7c65e320..b9b2d3b39d 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-generator.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-generator.ts @@ -6,6 +6,13 @@ import { TargetOutput } from './params' export class TransactionGenerator { private static txSerializedSizeInBlockWithoutInputs = (outputLength: number) : number => { + /* + * add a transaction to block need 4 Bytes for offset + * a transaction with empty inputs/outputs/cellDeps/header/outputs_data/witnesses need 68 Bytes + * every cellDep need 37 Bytes, transaction in Neuron only one cellDep + * every output without typeScript & with lock in secp need 97 Bytes and 4 Bytes for offset (add to transaction) + * every outputsData in "0x" need 4 Bytes and 4 Bytes for offset + */ return 4 + 68 + 37 * 1 + (4 + 97 + 4 + 4) * outputLength }