diff --git a/packages/neuron-wallet/src/entities/Input.ts b/packages/neuron-wallet/src/entities/Input.ts index 3995eb5d38..4eb984b966 100644 --- a/packages/neuron-wallet/src/entities/Input.ts +++ b/packages/neuron-wallet/src/entities/Input.ts @@ -63,6 +63,8 @@ export default class Input extends BaseEntity { return { previousOutput: this.previousOutput(), args: this.args, + capacity: this.capacity, + lockHash: this.lockHash, } } } diff --git a/packages/neuron-wallet/src/entities/Transaction.ts b/packages/neuron-wallet/src/entities/Transaction.ts index 9281dd1288..1fdbd86b56 100644 --- a/packages/neuron-wallet/src/entities/Transaction.ts +++ b/packages/neuron-wallet/src/entities/Transaction.ts @@ -1,5 +1,5 @@ import { Entity, BaseEntity, PrimaryColumn, Column, OneToMany } from 'typeorm' -import { Witness, OutPoint } from '../appTypes/types' +import { Witness, OutPoint, Transaction as TransactionInterface } from '../appTypes/types' import InputEntity from './Input' import OutputEntity from './Output' @@ -46,4 +46,18 @@ export default class Transaction extends BaseEntity { @OneToMany(_type => OutputEntity, output => output.transaction) outputs!: OutputEntity[] + + public toInterface(): TransactionInterface { + return { + hash: this.hash, + version: this.version, + deps: this.deps, + inputs: this.inputs.map(input => input.toInterface()), + outputs: this.outputs.map(output => output.toInterface()), + timestamp: this.timestamp, + blockNumber: this.blockNumber, + blockHash: this.blockHash, + witnesses: this.witnesses, + } + } } diff --git a/packages/neuron-wallet/src/services/transactions.ts b/packages/neuron-wallet/src/services/transactions.ts index 1423052ebf..4a4faa9314 100644 --- a/packages/neuron-wallet/src/services/transactions.ts +++ b/packages/neuron-wallet/src/services/transactions.ts @@ -149,21 +149,7 @@ export default class TransactionsService { return undefined } - const transaction: Transaction = { - ...tx, - inputs: tx.inputs.map(i => { - return { - ...i, - previousOutput: i.previousOutput(), - } - }), - outputs: tx.outputs.map(o => { - return { - ...o, - outPoint: o.outPoint(), - } - }), - } + const transaction: Transaction = tx.toInterface() return transaction }