Constructor
new Bitcoin(settingsopt)
Creates an instance of the Bitcoin service.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
settings |
Object |
<optional> |
Map of configuration options for the Bitcoin service.
Properties
|
- Source:
Extends
Members
UAString
User Agent string for the Bitcoin P2P network.
- Source:
height
Chain height (`=== length - 1`)
- Source:
tip
Chain tip (block hash of the chain with the most Proof of Work)
- Source:
Methods
(async) _GET(path) → {Promise}
Retrieve a value from the Service's state.
Parameters:
Name | Type | Description |
---|---|---|
path |
String | Path of the value to retrieve. |
- Overrides:
- Source:
Returns:
Resolves with the result.
- Type
- Promise
(async) _PUT(path, value, commitopt) → {Promise}
Store a value in the Service's state.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
path |
String | Path to store the value at. | ||
value |
Object | Document to store. | ||
commit |
Boolean |
<optional> |
false | Sign the resulting state. |
- Overrides:
- Source:
Returns:
Resolves with with stored document.
- Type
- Promise
(async) _buildPSBT(options) → {PSBT}
Create a Partially-Signed Bitcoin Transaction (PSBT).
Parameters:
Name | Type | Description |
---|---|---|
options |
Object | Parameters for the PSBT. |
- Source:
Returns:
Instance of the PSBT.
- Type
- PSBT
(async) _connectSPV()
Initiate outbound connections to configured SPV nodes.
- Source:
(async) _createContractProposal(options) → {ContractProposal}
Creates an unsigned Bitcoin transaction.
Parameters:
Name | Type | Description |
---|---|---|
options |
Object |
- Source:
Returns:
Instance of the proposal.
- Type
- ContractProposal
(async) _handleBlockFromSPV(msg)
Hand a Block message as supplied by an SPV client.
Parameters:
Name | Type | Description |
---|---|---|
msg |
BlockMessage | A Message as passed by the SPV source. |
- Source:
(async) _handleCommittedBlock(block)
Receive a committed block.
Parameters:
Name | Type | Description |
---|---|---|
block |
Block | Block to handle. |
- Source:
(async) _handlePeerPacket(msg)
Process a message from a peer in the Bitcoin network.
Parameters:
Name | Type | Description |
---|---|---|
msg |
PeerPacket | Message from peer. |
- Source:
(async) _handleTransactionFromSPV(tx)
Verify and interpret a BitcoinTransaction, as received from an
SPVSource.
Parameters:
Name | Type | Description |
---|---|---|
tx |
BitcoinTransaction | Incoming transaction from the SPV source. |
- Source:
(async) _prepareTransaction(obj)
Prepares a Transaction for storage.
Parameters:
Name | Type | Description |
---|---|---|
obj |
Transaction | Transaction to prepare. |
- Source:
(async) _processSpendMessage(message) → {BitcoinTransactionID}
Process a spend message.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
message |
SpendMessage | Generic-level message for spending.
Properties
|
- Source:
Returns:
Hex-encoded representation of the transaction ID.
- Type
- BitcoinTransactionID
(async) _registerActor(actor) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
actor |
Object | Instance of the Actor. |
- Overrides:
- Source:
Returns:
Resolves upon successful registration.
- Type
- Promise
(async) _requestBlockAtHeight(height) → {Object}
Retrieve the equivalent to `getblockhash` from Bitcoin Core.
Parameters:
Name | Type | Description |
---|---|---|
height |
Number | Height of block to retrieve. |
- Source:
Returns:
The block hash.
- Type
- Object
(async) _send(message)
Sends a message.
Parameters:
Name | Type | Description |
---|---|---|
message |
Mixed | Message to send. |
- Overrides:
- Source:
(async) _subscribeToShard(shard)
Attach event handlers for a supplied list of addresses.
Parameters:
Name | Type | Description |
---|---|---|
shard |
Shard | List of addresses to monitor. |
- Source:
beat() → {Service}
Compute latest state.
- Overrides:
- Source:
Fires:
- Message#event:beat
Returns:
- Type
- Service
(async) broadcast(tx)
Broadcast a transaction to the Bitcoin network.
Parameters:
Name | Type | Description |
---|---|---|
tx |
TX | Bitcoin transaction |
- Source:
(async) connect(addr)
Connect to a Fabric Peer.
Parameters:
Name | Type | Description |
---|---|---|
addr |
String | Address to connect to. |
- Overrides:
- Source:
get(path) → {Mixed}
Retrieve a key from the State.
Parameters:
Name | Type | Description |
---|---|---|
path |
Path | Key to retrieve. |
- Overrides:
- Source:
Returns:
Returns the target value if found, otherwise null.
- Type
- Mixed
handler(message) → {Service}
Default route handler for an incoming message. Follows the Activity
Streams 2.0 spec: https://www.w3.org/TR/activitystreams-core/
Parameters:
Name | Type | Description |
---|---|---|
message |
Activity | Message object. |
- Overrides:
- Source:
Returns:
Chainable method.
- Type
- Service
init()
Called by Web Components.
TODO: move to @fabric/http/types/spa
- Overrides:
- Source:
lock(durationopt) → {Boolean}
Attempt to acquire a lock for `duration` seconds.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
duration |
Number |
<optional> |
1000 | Number of milliseconds to hold lock. |
- Overrides:
- Source:
Returns:
true if locked, false if unable to lock.
- Type
- Boolean
(async) route(msg) → {Promise}
Parameters:
Name | Type | Description |
---|---|---|
msg |
Message | Explicit Fabric Message. |
- Overrides:
- Source:
Returns:
Resolves with resulting State.
- Type
- Promise
(async) send(channel, message) → {Service}
Send a message to a channel.
Parameters:
Name | Type | Description |
---|---|---|
channel |
String | Channel name to which the message will be sent. |
message |
String | Content of the message to send. |
- Overrides:
- Source:
Returns:
Chainable method.
- Type
- Service
set(path) → {Mixed}
Set a key in the State to a particular value.
Parameters:
Name | Type | Description |
---|---|---|
path |
Path | Key to retrieve. |
- Overrides:
- Source:
Returns:
- Type
- Mixed
(async) start()
Start the Bitcoin service, including the initiation of outbound requests.
- Overrides:
- Source:
(async) stop()
Stop the Bitcoin service.
- Source:
tick() → {Number}
Move forward one clock cycle.
- Overrides:
- Source:
Returns:
- Type
- Number
trust(source) → {Service}
Explicitly trust all events from a known source.
Parameters:
Name | Type | Description |
---|---|---|
source |
EventEmitter | Emitter of events. |
- Overrides:
- Source:
Returns:
Instance of Service after binding events.
- Type
- Service