Skip to content

Commit

Permalink
chore: notes for transaction size
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Oct 22, 2019
1 parent bf396e5 commit ea1a93d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ea1a93d

Please sign in to comment.