Constructor
new MTX(optionsopt, nullable)
Create a mutable transaction.
Extends:
- TX
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> <nullable> |
Properties:
Name | Type | Description |
---|---|---|
changeIndex |
Number | |
view |
CoinView |
- Source:
Extends
- TX
Methods
(static) fromTX(tx) → {MTX}
Instantiate MTX from TX.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- MTX
(static) isMTX(obj) → {Boolean}
Test whether an object is an MTX.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
- Source:
Returns:
- Type
- Boolean
addCoin(coin) → {Input}
Add a coin as an input. Note that this will add the coin to the internal coin viewpoint.
Parameters:
Name | Type | Description |
---|---|---|
coin |
Coin |
- Source:
Returns:
- Type
- Input
Example
mtx.addCoin(Coin.fromTX(tx, 0, -1));
addInput(options) → {Input}
Add an input to the transaction.
Parameters:
Name | Type | Description |
---|---|---|
options |
Input | Object |
- Source:
Returns:
- Type
- Input
Example
mtx.addInput({ prevout: { hash: ... }, witness: ... });
mtx.addInput(new Input());
addOutpoint(outpoint) → {Input}
Add an outpoint as an input.
Parameters:
Name | Type | Description |
---|---|---|
outpoint |
Outpoint | Object |
- Source:
Returns:
- Type
- Input
Example
mtx.addOutpoint({ hash: ..., index: 0 });
mtx.addOutpoint(new Outpoint(hash, index));
addOutput(addr, valueopt, nullable) → {Output}
Add an output.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
addr |
Address | Output | Object | Address or output options. |
|
value |
AmountValue |
<optional> <nullable> |
- Source:
Returns:
- Type
- Output
Example
mtx.addOutput(new Output());
mtx.addOutput({ address: ..., value: 100000 });
mtx.addOutput(address, 100000);
addTX(tx, index, heightnullable) → {Input}
Add a transaction as an input. Note that this will add the coin to the internal coin viewpoint.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tx |
TX | ||
index |
Number | ||
height |
Number |
<nullable> |
- Source:
Returns:
- Type
- Input
Example
mtx.addTX(tx, 0);
avoidFeeSniping(height)
Avoid fee sniping.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | Current chain height. |
- Source:
- See:
-
- bitcoin/src/wallet/wallet.cpp
check(flagsopt, nullable)
Verify all transaction inputs.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
flags |
VerifyFlags |
<optional> <nullable> |
STANDARD_VERIFY_FLAGS |
- Source:
Throws:
-
on invalid inputs
- Type
- ScriptError
checkAsync(flagsopt, nullable, poolopt, nullable) → {Promise}
Verify the transaction inputs on the worker pool (if workers are enabled).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
flags |
VerifyFlags |
<optional> <nullable> |
STANDARD_VERIFY_FLAGS | |
pool |
WorkerPool |
<optional> <nullable> |
- Source:
Returns:
- Type
- Promise
checkInputs(height, network) → {Array}
Perform contextual checks to verify input, output, and fee values, as well as coinbase spend maturity (coinbases can only be spent 100 blocks or more after they're created). Note that this function is consensus critical.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | Height at which the transaction is being spent. In the mempool this is the chain height plus one at the time it entered the pool. |
network |
Network |
- Source:
Returns:
[fee, reason, score]
- Type
- Array
commit() → {Array}
Convert the MTX to a TX.
- Source:
Returns:
[tx, view]
- Type
- Array
(async) estimateSize(estimatenullable) → {Promise.<Number>}
Estimate maximum possible size.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
estimate |
function |
<nullable> |
Input script size estimator. |
- Source:
Returns:
- Type
- Promise.<Number>
format() → {Object}
Inspect the transaction.
- Source:
Returns:
- Type
- Object
fromJSON(json)
Inject properties from a json object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object |
- Source:
fromOptions(options)
Inject properties from options object.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
fromTX(tx) → {MTX}
Instantiate MTX from TX.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX |
- Source:
Returns:
- Type
- MTX
(async) fund(coins, options) → {Promise.<CoinSelector>}
Select coins and fill the inputs.
Parameters:
Name | Type | Description |
---|---|---|
coins |
Array.<Coin> | |
options |
Object | See MTX#selectCoins options. |
- Source:
Returns:
- Type
- Promise.<CoinSelector>
getAddresses() → {Array.<Address>}
Get all addresses.
- Source:
Returns:
addresses
- Type
- Array.<Address>
getFee() → {AmountValue}
Calculate the fee for the transaction.
- Source:
Returns:
fee (zero if not all coins are available).
- Type
- AmountValue
getHashes() → {Array.<Hash>}
Get all address hashes.
- Source:
Returns:
hashes
- Type
- Array.<Hash>
getInputAddresses() → {Array.<Address>}
Get all input addresses.
- Source:
Returns:
addresses
- Type
- Array.<Address>
getInputHashes() → {Array.<Hash>}
Get all input address hashes.
- Source:
Returns:
hashes
- Type
- Array.<Hash>
getInputValue() → {AmountValue}
Calculate the total input value.
- Source:
Returns:
value
- Type
- AmountValue
getJSON(network) → {Object}
Convert transaction to JSON.
Parameters:
Name | Type | Description |
---|---|---|
network |
Network |
- Source:
Returns:
- Type
- Object
getSigops() → {Number}
Calculate virtual sigop count.
- Source:
Returns:
sigop count
- Type
- Number
getSigopsSize() → {Number}
Calculate the virtual size of the transaction (weighted against bytes per sigop cost).
- Source:
Returns:
vsize
- Type
- Number
hasCoins() → {Boolean}
Test whether the transaction has all coins available/filled.
- Source:
Returns:
- Type
- Boolean
inject(mtx) → {this}
Clone the transaction. Note that this will not carry over the view.
Parameters:
Name | Type | Description |
---|---|---|
mtx |
this |
- Source:
Returns:
- Type
- this
isInputSigned(index, coin) → {Boolean}
Test whether an input is fully-signed.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | |
coin |
Coin | Output |
- Source:
Returns:
- Type
- Boolean
isSigned() → {Boolean}
Test whether the transaction is fully-signed.
- Source:
Returns:
- Type
- Boolean
isVectorSigned(prev, vector) → {Boolean}
Test whether a vector is fully-signed.
Parameters:
Name | Type | Description |
---|---|---|
prev |
Script | |
vector |
Stack |
- Source:
Returns:
- Type
- Boolean
scriptInput(index, coin, ring) → {Boolean}
Build input script (or witness) templates (with OP_0 in place of signatures).
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | Input index. |
coin |
Coin | Output | |
ring |
KeyRing |
- Source:
Returns:
Whether the script was able to be built.
- Type
- Boolean
scriptVector(prev, ring) → {Stack}
Build script for a single vector based on a previous script.
Parameters:
Name | Type | Description |
---|---|---|
prev |
Script | |
ring |
KeyRing |
- Source:
Returns:
- Type
- Stack
selectCoins(coins, optionsnullable) → {Promise.<CoinSelector>}
Select necessary coins based on total output value.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
coins |
Array.<Coin> | ||
options |
Object |
<nullable> |
- Source:
Throws:
on not enough funds available.
Returns:
- Type
- Promise.<CoinSelector>
setLocktime(locktime, secondsopt, nullable)
Set locktime and sequences appropriately.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
locktime |
Number | ||
seconds |
Boolean |
<optional> <nullable> |
- Source:
setSequence(index, locktime, secondsnullable)
Set sequence locktime.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
Number | Input index. |
|
locktime |
Number | ||
seconds |
Boolean |
<nullable> |
- Source:
sign(ring, type) → {Number}
Built input scripts (or witnesses) and sign the inputs.
Parameters:
Name | Type | Description |
---|---|---|
ring |
KeyRing | Address used to sign. The address must be able to redeem the coin. |
type |
SighashType |
- Source:
Returns:
Number of inputs signed.
- Type
- Number
(async) signAsync(ring, typenullable, poolnullable) → {Promise}
Sign the transaction inputs on the worker pool (if workers are enabled).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ring |
KeyRing | ||
type |
SighashType |
<nullable> |
|
pool |
WorkerPool |
<nullable> |
- Source:
Returns:
- Type
- Promise
signInput(index, coin, ring, type) → {Boolean}
Sign an input.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | Index of input being signed. |
coin |
Coin | Output | |
ring |
KeyRing | Private key. |
type |
SighashType |
- Source:
Returns:
Whether the input was able to be signed.
- Type
- Boolean
(async) signInputAsync(index, coin, ring, typenullable, poolopt, nullable) → {Promise}
Sign a transaction input on the worker pool (if workers are enabled).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
index |
Number | ||
coin |
Coin | Output | ||
ring |
KeyRing | ||
type |
SighashType |
<nullable> |
|
pool |
WorkerPool |
<optional> <nullable> |
- Source:
Returns:
- Type
- Promise
signVector(prev, vector, sig, ring) → (nullable) {Stack}
Add a signature to a vector based on a previous script.
Parameters:
Name | Type | Description |
---|---|---|
prev |
Script | |
vector |
Stack | |
sig |
Buffer | |
ring |
KeyRing |
- Source:
Returns:
- Type
- Stack
sortMembers()
Sort inputs and outputs according to BIP69.
- Source:
- See:
subtractFee(fee)
Attempt to subtract a fee from all outputs evenly.
Parameters:
Name | Type | Description |
---|---|---|
fee |
AmountValue |
- Source:
subtractIndex(index, fee)
Attempt to subtract a fee from a single output.
Parameters:
Name | Type | Description |
---|---|---|
index |
Number | |
fee |
AmountValue |
- Source:
template(ring) → {Number}
Build input scripts (or witnesses).
Parameters:
Name | Type | Description |
---|---|---|
ring |
KeyRing | Address used to sign. The address must be able to redeem the coin. |
- Source:
Returns:
Number of inputs templated.
- Type
- Number
toJSON() → {Object}
Convert transaction to JSON.
- Source:
Returns:
- Type
- Object
toTX() → {TX}
Convert the MTX to a TX.
- Source:
Returns:
- Type
- TX
verify(flagsopt, nullable) → {Boolean}
Verify all transaction inputs.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
flags |
VerifyFlags |
<optional> <nullable> |
STANDARD_VERIFY_FLAGS |
- Source:
Returns:
Whether the inputs are valid.
- Type
- Boolean
(async) verifyAsync(flagsopt, nullable, poolopt, nullable) → {Promise}
Verify the transaction inputs on the worker pool (if workers are enabled).
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
flags |
VerifyFlags |
<optional> <nullable> |
STANDARD_VERIFY_FLAGS | |
pool |
WorkerPool |
<optional> <nullable> |
- Source:
Returns:
- Type
- Promise
verifyInputs(height, network) → {Boolean}
Perform contextual checks to verify input, output, and fee values, as well as coinbase spend maturity (coinbases can only be spent 100 blocks or more after they're created). Note that this function is consensus critical.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | Height at which the transaction is being spent. In the mempool this is the chain height plus one at the time it entered the pool. |
network |
Network |
- Source:
Returns:
- Type
- Boolean