Skip to content

SPV RPC Calls

Peter John Bushnell edited this page Apr 7, 2021 · 16 revisions

spv_claimhtlc
spv_createanchor
spv_createanchortemplate
spv_createhtlc
spv_decodehtlcscript
spv_dumpprivkey
spv_estimateanchorcost
spv_getaddresspubkey
spv_getbalance
spv_gethtlcseed
spv_getnewaddress
spv_getrawtransaction
spv_gettxconfirmations
spv_listanchors
spv_listanchorauths
spv_listanchorrewardconfirms
spv_listanchorrewards
spv_listanchorsunrewarded
spv_listanchorspending
spv_listhtlcoutputs
spv_listtransactions
spv_refundhtlc
spv_rescan
spv_sendrawtx
spv_sendtoaddress
spv_syncstatus

spv_claimhtlc

Claims all coins in HTLC address

Arguments  
scriptaddress             string    HTLC address  
destinationaddress        string    Destination for funds in the HTLC  
seed                      string    Seed that was used to generate the hash in the HTLC  
feerate                   number    Feerate (satoshis) per KB (Default: 10000)  

Results  
{  
  txid                    string    The transaction id  
  sendmessage             string    Send message result  
}  

spv_createanchor

Creates (and optional submits to bitcoin blockchain) an anchor
tx with latest possible (every 15th) authorized blockhash. The
first argument is the specific UTXOs to spend.

Arguments  
inputs                    JSON array of objects containing  
    txid                  string    The transaction id of the bitcoin UTXO to spend  
    vout                  number    The output index to spend in UTXO  
    amount                number    Amount of output in satoshis  
    privkey               string    WIF private key of bitcoin for signing this output  
rewardAddress             string    User's P2PKH address (in DeFi chain) for reward  
send                      bool      Send it to btc network (Default = true)  
feerate                   number    Feerate (satoshis) per 1000 bytes (Default = 1000)  

Results  
txHex                     string    The hex-encoded raw transaction with signature(s)  
txHash                    string    The hex-encoded transaction hash  

spv_createanchortemplate

Creates an anchor tx template with latest possible (every 15th) authorized blockhash.

Argument  
rewardAddress             string    User's P2PKH address (in DeFi chain) for reward  

Result  
txHex                     string    The hex-encoded raw transaction with signature(s)  

spv_createhtlc

Creates a Bitcoin address whose funds can be unlocked with a seed or as a refund.
It returns a json object with the address and redeemScript.

Arguments  
seller_key                string    The public key of the possessor of the seed  
refund_key                string    The public key of the recipient of the refund  
timeout                   string    Timeout of the contract (denominated in blocks) relative to its placement in the blockchain  
hash                      string    SHA256 hash of the seed. If none provided one will be generated  

Results  
{  
    address               string    The value of the new Bitcoin address.  
    redeemscript          string    Hex-encoded redemption script  
    seed                  string    Hex-encoded seed if no seed provided
    seedhash              string    Hex-encoded seed hash if no seed provided  
}  

spv_decodehtlcscript

Decode and return value in a HTLC redeemscript

Argument  
redeemscript              string    The HTLC redeemscript  

Results  
{  
    sellerkey             string    Seller public key  
    buyerkey              string    Buyer public key  
    blocks                number    Locktime in number of blocks  
    hash                  string    Hash of the seed  
}  

spv_dumpprivkey

Reveals the private key corresponding to 'address'

Argument  
address                   string    The BTC address for the private key  

Result  
key                       string    The private key  

spv_estimateanchorcost

Estimates current anchor cost with default fee, one input and one change output.

Argument
feerate                   number    Feerate (satoshis) per 1000 bytes (Default = 1000)

Result
cost                      number    Estimated anchor cost (satoshis)

spv_getaddresspubkey

Return raw pubkey for Bitcoin address if in SPV wallet

Argument
address                   string    Bitcoin address

Result
pubkey                    string    Raw pubkey hex

spv_getbalance

Returns the Bitcoin balance of the SPV wallet

Result
amount                    number    The total amount in BTC received in the SPV wallet

spv_gethtlcseed

Returns the HTLC secret if available

Argument
address                   string    HTLC address

Result
secret                    string    Returns HTLC seed

spv_getnewaddress

Creates and adds a Bitcoin address to the SPV wallet

Result
address                   string    Returns a new Bitcoin address

spv_getrawtransaction

Return the raw transaction data

Argument
txid                      string    The transaction id

Result
data                      string    The serialized, hex-encoded data for 'txid'

spv_gettxconfirmations

Reports tx confirmations (if any)...

Argument
txhash                    string    Hash of tx to look for

Result
count                     number    Tx confirmations. Zero if not confirmed yet (mempooled?) and -1 if not found

spv_listanchors

List anchors (if any)

Arguments
minBtcHeight              number    min btc height, optional (default = -1)
maxBtcHeight              number    max btc height, optional (default = -1)"
minConfs                  number    min anchor confirmations, optional (default = -1)
maxConfs                  number    mimaxn anchor confirmations, optional (default = -1)

Result
array                     Returns array of anchors

spv_listanchorauths

List anchor auths (if any)

Result
array                     Returns array of anchor auths

spv_listanchorrewardconfirms

List anchor reward confirms (if any)

Result
array                     Returns array of anchor confirms

spv_listanchorauths

List anchor rewards (if any)

Result
array                     Returns array of anchor rewards

spv_listanchorsunrewarded

List anchors that have yet to be paid

Result
array                     Returns array of unrewarded anchors

spv_listanchorspending

List pending anchors (if any). Pending anchors are waiting on
chain context to be fully validated, for example, anchors read
from SPV while the blockchain is still syncing.

Result
array                     Returns array of pending anchors

spv_listhtlcoutputs

List all outputs related to HTLC addresses in the wallet

Argument
address                   string    HTLC address to filter results

Result
array                     JSON array of transaction details
  txid                    string    The transaction id
  vout                    number    Output relating to the HTLC address\
  address                 string    HTLC address
  confirms                number    Number of confirmations
    spent                 JSON object containing spent info
    txid                  string    Transaction id spending this output
    confirms              number    Number of spent confirmations

spv_listtransactions

Returns an array of all Bitcoin transaction hashes

Result
array                     array of string
  txid                    string    The transaction id

spv_refundhtlc

Refunds all coins in HTLC address

Arguments  
scriptaddress             string    HTLC address  
destinationaddress        string    Destination for funds in the HTLC  
feerate                   number    Feerate (satoshis) per KB (Default: 10000)  

Results  
{  
  txid                    string    The transaction id  
  sendmessage             string    Send message result  
}  

spv_rescan

Rescan from block height.

Argument
height                    number    Block height or ('tip' minus 'height') if negative)

spv_sendrawtx

Sending raw tx to Bitcoin blockchain

Argument
rawtx                    string    The hex-encoded raw transaction with signature

spv_sendtoaddress

Send a Bitcoin amount to a given address.

Arguments
address                  string    The Bitcoin address to send to
amount                   number    The amount in BTC to send. eg 0.1
feerate                  number    Feerate (satoshis) per KB (Default: 10000)

Results
{  
  txid                   string    The transaction id  
  sendmessage            string    Send message result  
}  

spv_syncstatus

Returns spv sync status

Results
{  
  connected              bool     Connection status  
  current                number   Last synced block
  estimated              number   Estimated chain height (as reported by peers)
}