new Coin(tx/options, indexnullable)
Represents an unspent output.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
tx/options |
TX | NakedCoin | Coin | TX or options object. |
|
index |
Number |
<nullable> |
Output index. |
Properties:
Name | Type | Description |
---|---|---|
version |
Number | Transaction version. |
height |
Number | Transaction height (-1 if unconfirmed). |
value |
BN | Output value in satoshis. |
script |
Script | Output script. |
coinbase |
Boolean | Whether the containing transaction is a coinbase. |
hash |
Hash | Transaction hash. |
index |
Number | Output index. |
- Source:
Example
new Coin(tx, i);
new Coin(options);
Extends
Methods
(static) _fromExtended(data, encnullable) → {NakedCoin}
Parse an coin in "extended" serialization format.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
- A "naked" coin object.
- Type
- NakedCoin
(static) _fromJSON() → {NakedCoin}
Handle a deserialized JSON coin object.
- Source:
Returns:
A "naked" coin (a plain javascript object which is suitable for passing to the Coin constructor).
- Type
- NakedCoin
(static) _fromRaw(data, encnullable) → {NakedCoin}
Parse a serialized coin.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
A "naked" coin object.
- Type
- NakedCoin
(static) fromExtended(data, encnullable) → {Coin}
Instantiate a coin from a Buffer in "extended" serialization format.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
- Type
- Coin
(static) fromJSON(json) → {Coin}
Instantiate an Coin from a jsonified coin object.
Parameters:
Name | Type | Description |
---|---|---|
json |
Object | The jsonified coin object. |
- Source:
Returns:
- Type
- Coin
(static) fromRaw(data, encnullable) → {Coin}
Instantiate an coin from a serialized Buffer.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
Buffer | ||
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
- Type
- Coin
(static) isCoin(obj) → {Boolean}
Test an object to see if it is a Coin.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Object |
- Source:
Returns:
- Type
- Boolean
getAddress() → (nullable) {String}
Get the address.
- Inherited From:
- Source:
Returns:
address
- Type
- String
getAge(heightnullable) → {Number}
Calculate coin age. This is slightly different from confirmations. If the confirmations are incalculable, age is zero. If the age is non-zero, 1 is added to the age.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
Current chain height. Network height is used if not passed in. |
- Source:
Returns:
age
- Type
- Number
getConfirmations(heightnullable) → {Number}
Calculate number of confirmations since coin was created.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
height |
Number |
<nullable> |
Current chain height. Network height is used if not passed in. |
- Source:
Returns:
- Type
- Number
getType() → {String}
Get the script type.
- Inherited From:
- Source:
Returns:
type
- Type
- String
inspect() → {Object}
Convert the coin to a more user-friendly object.
- Overrides:
- Source:
Returns:
- Type
- Object
test(addressMap) → {Boolean}
Test the output against an address, an array of addresses, or a map of addresses.
Parameters:
Name | Type | Description |
---|---|---|
addressMap |
String | Array.<String> | Object |
- Inherited From:
- Source:
Returns:
Whether the output matched.
- Type
- Boolean
toExtended(encnullable) → {Buffer|String}
Serialize the coin to an "extended" format, including both the hash and the index.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Encoding, can be |
- Source:
Returns:
- Type
- Buffer | String
toJSON() → {Object}
Convert the coin to an object suitable for JSON serialization. Note that the hash will be reversed to abide by bitcoind's legacy of little-endian uint256s.
- Overrides:
- Source:
Returns:
- Type
- Object
toRaw(encnullable) → {Buffer|String}
Serialize the coin.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enc |
String |
<nullable> |
Encoding, can be |
- Overrides:
- Source:
Returns:
- Type
- Buffer | String