Spv API
import {JsonRpcClient} from '@defichain/jellyfish-api-jsonrpc'
const client = new JsonRpcClient('http://foo:bar@localhost:8554')
// Using client.spv.
const something = await client.spv.method()
getNewAddress
Creates and adds a Bitcoin address to the SPV wallet.
interface spv {
getNewAddress (): Promise<string>
}
getAddressPubKey
Returns a Bitcoin address's public key.
interface spv {
getAddressPubKey (address: string): Promise<string>
}
listReceivedByAddress
List balances by receiving address.
interface spv {
listReceivedByAddress (minConfirmation: number = 1, address?: string): Promise<ReceivedByAddressInfo[]>
}
interface ReceivedByAddressInfo {
address: string
type: string
amount: BigNumber
confirmations: number
txids: string[]
}
sendToAddress
Send a Bitcoin amount to a given address.
interface spv {
sendToAddress (address: string, amount: BigNumber, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<SendMessageResult>
}
interface SpvDefaultOptions {
feeRate?: BigNumber
}
interface SendMessageResult {
txid: string
sendmessage: string
}
createHtlc
Creates a Bitcoin address whose funds can be unlocked with a seed or as a refund.
interface spv {
createHtlc (receiverPubKey: string, ownerPubKey: string, options: CreateHtlcOptions): Promise<CreateHtlcResult>
}
interface CreateHtlcOptions {
timeout: string
seedhash?: string
}
interface CreateHtlcResult {
address: string
redeemScript: string
seed?: number
seedhash?: string
}
decodeHtlcScript
Decode and return value in a HTLC redeemscript.
interface spv {
decodeHtlcScript (redeemScript: string): Promise<DecodeHtlcResult>
}
interface DecodeHtlcResult {
sellerkey: string
buyerkey: string
blocks: number
hash: string
}
claimHtlc
Claims all coins in HTLC address.
interface spv {
claimHtlc (scriptAddress: string, destinationAddress: string, options: ClaimHtlcOptions): Promise<SendMessageResult>
}
interface ClaimHtlcOptions {
seed: string
feeRate?: BigNumber
}
interface SendMessageResult {
txid: string
sendmessage: string
}
getHtlcSeed
Returns the HTLC secret if available.
interface spv {
getHtlcSeed (address: string): Promise<string>
}
refundHtlc
Refunds all coins in HTLC address.
interface spv {
refundHtlc (scriptAddress: string, destinationAddress: string, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<SendMessageResult>
}
interface SpvDefaultOptions {
feeRate?: BigNumber
}
interface SendMessageResult {
txid: string
sendmessage: string
}
refundHtlcAll
Gets all HTLC contracts stored in wallet and creates refunds transactions for all that have expired
interface spv {
refundHtlcAll (destinationAddress: string, options: SpvDefaultOptions = { feeRate: new BigNumber('10000') }): Promise<string[]>
}
interface SpvDefaultOptions {
feeRate?: BigNumber
}
listHtlcOutputs
List all outputs related to HTLC addresses in the wallet.
interface spv {
listHtlcOutputs (scriptAddress?: string): Promise<ListHtlcsOutputsResult[]>
}
interface SpentInfo {
txid: string
confirms: number
}
interface ListHtlcsOutputsResult {
txid: string
vout: number
amount: BigNumber
address: string
confirms: number
spent: SpentInfo
}
listAnchorRewardConfirms
List anchor reward confirms.
interface spv {
listAnchorRewardConfirms (): Promise<ListAnchorRewardConfirmsResult[]>
}
export interface ListAnchorRewardConfirmsResult {
btcTxHeight: number
btcTxHash: string
anchorHeight: number
dfiBlockHash: string
prevAnchorHeight: number
rewardAddress: string
confirmSignHash: string
signers: number
}
listAnchorsUnrewarded
List unrewarded anchors.
interface spv {
listAnchorsUnrewarded (): Promise<ListAnchorsResult[]>
}
interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}
listAnchorRewards
List anchor rewards.
interface spv {
listAnchorRewards (): Promise<ListAnchorRewardsResult[]>
}
interface ListAnchorRewardsResult {
AnchorTxHash: string
RewardTxHash: string
}
createAnchor
Create, sign and send anchor tx, using only SPV API.
interface spv {
createAnchor (
createAnchorInputs: CreateAnchorInput[], rewardAddress: string, options: CreateAnchorOptions = { send: true, feerate: 1000 }
): Promise<CreateAnchorResult>
}
interface CreateAnchorInput {
txid: string
vout: number
amount: number
privkey: string
}
interface CreateAnchorOptions {
send?: boolean
feerate?: number
}
interface CreateAnchorResult {
txHex: string
txHash: string
defiHash: string
defiHeight: number
estimatedReward: BigNumber
cost: BigNumber
sendResult: number
sendMessage: string
}
listAnchors
List anchors.
interface spv {
listAnchors (
options: ListAnchorsOptions = { minBtcHeight: -1, maxBtcHeight: -1, minConfs: -1, maxConfs: -1, startBTCHeight: -1, limit: -1 }
): Promise<ListAnchorsResult[]>
}
interface ListAnchorsOptions {
minBtcHeight?: number
maxBtcHeight?: number
minConfs?: number
maxConfs?: number
startBTCHeight?: number
limit?: number
}
interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}
listAnchorsPending
List pending anchors in mempool.
interface spv {
listAnchorsPending (): Promise<ListAnchorsResult[]>
}
interface ListAnchorsResult {
btcBlockHeight: number
btcBlockHash: string
btcTxHash: string
previousAnchor: string
defiBlockHeight: number
defiBlockHash: string
rewardAddress: string
confirmations: number
signatures: number
active?: boolean
anchorCreationHeight?: number
}
listAnchorAuths
List anchor auths.
interface spv {
listAnchorAuths (): Promise<ListAnchorAuthsResult[]>
}
interface ListAnchorAuthsResult {
previousAnchor: string
blockHeight: number
blockHash: string
creationHeight: number
signers: number
signees?: string[]
}
setLastHeight
Set last height on BTC chain, use for testing purpose.
interface spv {
setLastHeight (height: number): Promise<void>
}