Package org.consensusj.bitcoin.services
Class WalletAppKitService
java.lang.Object
org.consensusj.bitcoin.services.WalletAppKitService
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BitcoinJsonRpc
- Direct Known Subclasses:
MicronautWalletAppKitService
Implement a subset of Bitcoin JSON RPC using a WalletAppKit
-
Field Summary
Modifier and TypeFieldDescriptionprotected final HexFormat
protected final org.bitcoinj.kits.WalletAppKit
protected final ObjectMapper
protected final org.bitcoinj.base.BitcoinNetwork
Fields inherited from interface org.consensusj.bitcoin.json.rpc.BitcoinJsonRpc
DEFAULT_MAX_CONF, DEFAULT_MIN_CONF
-
Constructor Summary
ConstructorDescriptionWalletAppKitService
(org.bitcoinj.kits.WalletAppKit walletAppKit) Construct from an (un-started)WalletAppKit
instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static WalletAppKitService
createTemporary
(org.bitcoinj.base.BitcoinNetwork network, org.bitcoinj.base.ScriptType scriptType, String walletBaseName) Create an instance in a temporary directory.static org.bitcoinj.kits.WalletAppKit
createTemporaryWallet
(org.bitcoinj.base.BitcoinNetwork network, org.bitcoinj.base.ScriptType scriptType, String walletBaseName) CompletableFuture
<org.bitcoinj.base.Coin> CompletableFuture
<org.bitcoinj.base.Sha256Hash> Partial implementation of `getblock` In the case where verbosity = 0, a block is returned without transactions (which is incorrect) For verbosity = 1, we return a BlockInfo, but some fields may be missing or incorrect, including a list of TXIDs For verbosity = 2, we are currently throwing an exception.CompletableFuture
<org.bitcoinj.base.Sha256Hash> getblockhash
(Integer blockNumber) Placeholder -- currently throws `UnsupportedOperationException`getblockheader
(String blockHashString, Boolean verbose) getblockheader2
(org.bitcoinj.base.Sha256Hash blockHash, Boolean verbose) getBlockInfo
(org.bitcoinj.base.Sha256Hash blockHash, BlockInfo.IncludeTxFlag includeTx) CompletableFuture
<org.bitcoinj.base.Address> org.bitcoinj.core.PeerGroup
help()
org.bitcoinj.base.Network
network()
protected <T> CompletableFuture
<T> result
(T result) CompletableFuture
<org.bitcoinj.base.Sha256Hash> sendrawtransaction
(String hex) CompletableFuture
<org.bitcoinj.base.Sha256Hash> sendtoaddress
(String toAddressString, Double amountDouble) Send coins to an addressCurrently all UTXOs must be present in the wallet andsighashtype
defaults to"ALL"
.void
start()
stop()
-
Field Details
-
hexFormat
-
network
-
kit
-
mapper
-
-
Constructor Details
-
WalletAppKitService
Construct from an (un-started)WalletAppKit
instance.- Parameters:
walletAppKit
- instance
-
-
Method Details
-
createTemporary
public static WalletAppKitService createTemporary(org.bitcoinj.base.BitcoinNetwork network, org.bitcoinj.base.ScriptType scriptType, String walletBaseName) Create an instance in a temporary directory. Useful for testing.- Parameters:
network
- network to operate onscriptType
- script type for walletwalletBaseName
- base name for the two wallet files- Returns:
- an un-started instance (use
start()
to start it)
-
createTemporaryWallet
public static org.bitcoinj.kits.WalletAppKit createTemporaryWallet(org.bitcoinj.base.BitcoinNetwork network, org.bitcoinj.base.ScriptType scriptType, String walletBaseName) -
start
-
network
-
getPeerGroup
-
help
- Specified by:
help
in interfaceBitcoinJsonRpc
-
stop
- Specified by:
stop
in interfaceBitcoinJsonRpc
-
getblockcount
- Specified by:
getblockcount
in interfaceBitcoinJsonRpc
-
getbestblockhash
- Specified by:
getbestblockhash
in interfaceBitcoinJsonRpc
-
getblockheader
- Specified by:
getblockheader
in interfaceBitcoinJsonRpc
-
getblockheader2
public CompletableFuture<JsonNode> getblockheader2(org.bitcoinj.base.Sha256Hash blockHash, Boolean verbose) -
getblock
Partial implementation of `getblock` In the case where verbosity = 0, a block is returned without transactions (which is incorrect) For verbosity = 1, we return a BlockInfo, but some fields may be missing or incorrect, including a list of TXIDs For verbosity = 2, we are currently throwing an exception.- Specified by:
getblock
in interfaceBitcoinJsonRpc
- Parameters:
blockHashString
- The hash of the block we are to return (as hex)verbosity
- Specifies the format to return (currently only `1` halfway works)- Returns:
- Either a `Block` or `BlockInfo` depending upon verbosity.
-
getblock2
public CompletableFuture<JsonNode> getblock2(org.bitcoinj.base.Sha256Hash blockHash, Integer verbosity) -
getblockhash
Placeholder -- currently throws `UnsupportedOperationException`- Specified by:
getblockhash
in interfaceBitcoinJsonRpc
- Parameters:
blockNumber
- The block height of the desired block- Returns:
- The Sha256Hash of the specified block
-
getconnectioncount
- Specified by:
getconnectioncount
in interfaceBitcoinJsonRpc
-
getblockchaininfo
- Specified by:
getblockchaininfo
in interfaceBitcoinJsonRpc
-
getnetworkinfo
- Specified by:
getnetworkinfo
in interfaceBitcoinJsonRpc
-
createrawtransaction
public CompletableFuture<String> createrawtransaction(List<Map<String, Object>> inputs, List<Map<String, String>> outputs) - Specified by:
createrawtransaction
in interfaceBitcoinJsonRpc
-
getnewaddress
- Specified by:
getnewaddress
in interfaceBitcoinJsonRpc
-
getbalance
- Specified by:
getbalance
in interfaceBitcoinJsonRpc
-
listunspent
public CompletableFuture<List<UnspentOutput>> listunspent(Integer minConf, Integer maxConf, List<String> addresses, Boolean includeUnsafe) - Specified by:
listunspent
in interfaceBitcoinJsonRpc
-
sendtoaddress
public CompletableFuture<org.bitcoinj.base.Sha256Hash> sendtoaddress(String toAddressString, Double amountDouble) Send coins to an address- Specified by:
sendtoaddress
in interfaceBitcoinJsonRpc
- Parameters:
toAddressString
- Address to send coins toamountDouble
- Amount to send- Returns:
- future that completes with a transaction hash/id when the tx is successfully relayed
-
sendrawtransaction
- Specified by:
sendrawtransaction
in interfaceBitcoinJsonRpc
-
signrawtransactionwithwallet
Description copied from interface:BitcoinJsonRpc
Currently all UTXOs must be present in the wallet andsighashtype
defaults to"ALL"
.- Specified by:
signrawtransactionwithwallet
in interfaceBitcoinJsonRpc
- Parameters:
hex
- hex-encoded unsigned raw transaction- Returns:
- signed raw transaction
-
getBlockInfo
public CompletableFuture<BlockInfo> getBlockInfo(org.bitcoinj.base.Sha256Hash blockHash, BlockInfo.IncludeTxFlag includeTx) -
result
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-