Add clone, addInputs, addOutputs

This commit is contained in:
junderw 2019-07-09 18:03:15 +09:00
parent b8c341dea0
commit 01c7ac39b6
No known key found for this signature in database
GPG key ID: B256185D3A971908
4 changed files with 221 additions and 152 deletions
ts_src

View file

@ -130,6 +130,13 @@ export class Psbt extends PsbtBase {
return this.inputs.length;
}
clone(): Psbt {
// TODO: more efficient cloning
const res = Psbt.fromBuffer(this.toBuffer());
res.opts = JSON.parse(JSON.stringify(this.opts));
return res;
}
setMaximumFeeRate(satoshiPerByte: number): void {
check32Bit(satoshiPerByte); // 42.9 BTC per byte IS excessive... so throw
this.opts.maximumFeeRate = satoshiPerByte;
@ -168,6 +175,11 @@ export class Psbt extends PsbtBase {
return this;
}
addInputs(inputDatas: TransactionInput[]): this {
inputDatas.forEach(inputData => this.addInput(inputData));
return this;
}
addInput(inputData: TransactionInput): this {
checkInputsForPartialSig(this.inputs, 'addInput');
const c = this.__CACHE;
@ -178,6 +190,11 @@ export class Psbt extends PsbtBase {
return this;
}
addOutputs(outputDatas: TransactionOutput[]): this {
outputDatas.forEach(outputData => this.addOutput(outputData));
return this;
}
addOutput(outputData: TransactionOutput): this {
checkInputsForPartialSig(this.inputs, 'addOutput');
const { address } = outputData as any;