add inputAmount and outputAmount to docs
This commit is contained in:
parent
b92fd915eb
commit
b685b5d28a
|
@ -24,6 +24,8 @@ var transaction = new Transaction()
|
|||
.sign(privkeySet) // Signs all the inputs it can
|
||||
```
|
||||
|
||||
You can obtain the input and output total amounts of the transaction in satoshis by accessing the fields `inputAmount` and `outputAmount`.
|
||||
|
||||
Now, this could just be serialized to hexadecimal ASCII values (`transaction.serialize()`) and sent over to the bitcoind reference client.
|
||||
|
||||
```bash
|
||||
|
@ -102,7 +104,7 @@ Some methods related to adding inputs are:
|
|||
- `from(utxos)`: same as above, but passing in an array of Unspent Outputs.
|
||||
- `from(utxo, publicKeys, threshold)`: add an input that spends a UTXO with a P2SH output for a Multisig script. The `publicKeys` argument is an array of public keys, and `threshold` is the number of required signatures in the Multisig script.
|
||||
* `addInput`: Performs a series of checks on an input and appends it to the end of the `input` vector and updates the amount of incoming bitcoins of the transaction.
|
||||
* `uncheckedAddInput`: adds an input to the end of the `input` vector and updates the `_inputAmount` without performing any checks.
|
||||
* `uncheckedAddInput`: adds an input to the end of the `input` vector and updates the `inputAmount` without performing any checks.
|
||||
|
||||
### PublicKeyHashInput
|
||||
|
||||
|
@ -131,7 +133,7 @@ The following methods are used to manage signatures for a transaction:
|
|||
|
||||
Outputs can be added by:
|
||||
|
||||
* The `addOutput(output)` method, which pushes an `Output` to the end of the `outputs` property and updates the `_outputAmount`. It also clears signatures (as the hash of the transaction may have changed) and updates the change output.
|
||||
* The `addOutput(output)` method, which pushes an `Output` to the end of the `outputs` property and updates the `outputAmount` field. It also clears signatures (as the hash of the transaction may have changed) and updates the change output.
|
||||
* The `to(address, amount)` method, that adds an output with the script that corresponds to the given address. Builds an output and calls the `addOutput` method.
|
||||
* Specifying a [change address](#Fee_calculation)
|
||||
|
||||
|
|
|
@ -64,13 +64,13 @@ describe('Transaction.Input', function() {
|
|||
input.toString();
|
||||
}).to.throw('Need a script to create an input');
|
||||
});
|
||||
it('fromJSON', function() {
|
||||
it('fromJSON should work', function() {
|
||||
var input = Input.fromJSON(coinbaseJSON);
|
||||
var otherInput = Input.fromJSON(otherJSON);
|
||||
should.exist(input);
|
||||
should.exist(otherInput);
|
||||
});
|
||||
it('fromObject', function() {
|
||||
it('fromObject should work', function() {
|
||||
var input = Input.fromJSON(coinbaseJSON);
|
||||
var obj = input.toObject();
|
||||
obj.script = new Buffer(obj.script, 'hex');
|
||||
|
@ -80,7 +80,7 @@ describe('Transaction.Input', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('_estimateSize', function() {
|
||||
it('_estimateSize returns correct size', function() {
|
||||
var input = new Input(output);
|
||||
input._estimateSize().should.equal(66);
|
||||
});
|
||||
|
|
|
@ -42,15 +42,6 @@ describe('Output', function() {
|
|||
expectEqualOutputs(output, deserialized);
|
||||
});
|
||||
|
||||
it('roundtrips to/from object', function() {
|
||||
var newOutput = new Output({
|
||||
satoshis: 50,
|
||||
script: new Script().add(0)
|
||||
});
|
||||
var otherOutput = new Output(newOutput.toObject());
|
||||
expectEqualOutputs(newOutput, otherOutput);
|
||||
});
|
||||
|
||||
it('can set a script from a buffer', function() {
|
||||
var newOutput = Output(output);
|
||||
newOutput.setScript(Script().add(0).toBuffer());
|
||||
|
@ -67,19 +58,32 @@ describe('Output', function() {
|
|||
'cabd5ac1ca10646e23fd5f51508 21 0x038282263212c609d9ea2a6e3e172de23' +
|
||||
'8d8c39cabd5ac1ca10646e23fd5f51508 OP_2 OP_CHECKMULTISIG OP_EQUAL')
|
||||
});
|
||||
|
||||
it('toBufferWriter', function() {
|
||||
output2.toBufferWriter().toBuffer().toString('hex')
|
||||
.should.equal('00ab904100000000485215038282263212c609d9ea2a6e3e172de2' +
|
||||
'38d8c39cabd5ac1ca10646e23fd5f5150815038282263212c609d9ea2a6e3e172d' +
|
||||
'e238d8c39cabd5ac1ca10646e23fd5f5150852ae87');
|
||||
});
|
||||
it('to/from JSON', function() {
|
||||
|
||||
it('roundtrips to/from object', function() {
|
||||
var newOutput = new Output({
|
||||
satoshis: 50,
|
||||
script: new Script().add(0)
|
||||
});
|
||||
var otherOutput = new Output(newOutput.toObject());
|
||||
expectEqualOutputs(newOutput, otherOutput);
|
||||
});
|
||||
|
||||
it('roundtrips to/from JSON', function() {
|
||||
var json = output2.toJSON();
|
||||
var o3 = new Output(json);
|
||||
o3.toJSON().should.equal(json);
|
||||
});
|
||||
|
||||
it('setScript fails with invalid input', function() {
|
||||
var out = new Output(output2.toJSON());
|
||||
out.setScript.bind(out, 45).should.throw('Invalid argument type: script');
|
||||
});
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue