nSPV
Introduction
nSPV enhances the normal "Simple Payment Verification" (SPV) technology available for a Smart Chain. To learn more about regular SPV technology, read this entry on the Bitcoin wiki.
nSPV leverages the dPoW security mechanism of the Indexchain Platform to enable secure and scalable super-lite "SPV" clients. An nSPV client network utilizes a smaller amount of computation and storage resources compared to a normal SPV network. For all Smart Chains that enable nSPV, full nodes on the network can serve the necessary data to nSPV nodes for the latter to have full wallet functionality.
All Indexchain-compatible Smart Chains, including the DIC main chain, can utilize this technology.
More details are available in the blog posts here and here.
Installation
<!---FIXME
Usage: nspv [COIN defaults to NSPV] (-c|continuous) (-i|-ips <ip,ip,...]>) (-m[--maxpeers] <int>) (-t[--testnet]) (-f <headersfile|0 for in mem only>) (-p <rpcport>) (-r[--regtest]) (-d[--debug]) (-s[--timeout] <secs>) <command> Supported commands: scan (scan blocks up to the tip, creates header.db file)
Examples: Sync up to the chain tip and stores all headers in headers.db (quit once synced):
nspv scan
Sync up to the chain tip and give some debug output during that process:
nspv -d scan
Sync up, show debug info, don't store headers in file (only in memory), wait for new blocks:
nspv -d -f 0 -c scan
--->
Enabling the nSPV Client
Copy the following code to the file named coins
(located at the root of the source directory).
(Change each value as appropriate for the desired Smart Chain.)
Property Descriptions
Name | Type | Description |
coin | (string) | the ticker of the coin |
asset | (string) | the |
fname | (string) | the full name of the Smart Chain |
rpcport | (number) | the RPC port the Smart Chain's daemon uses to receive RPC commands |
mm2 | (number) | set this value to |
p2p | (number) | the p2p port the Smart Chain's daemon uses to communicate with other nodes |
magic | (string) | the netmagic number for this Smart Chain. The decimal value of |
nSPV | (string) | the ip addresses of the nodes on the Smart Chain network |
::: tip
If you find that the direction of magic
is wrong, try reversing the order of the numbers.
:::
::: tip
The magic
number can also be seen in the terminal as a stdout
printout when the daemon is launched.
Example
:::
::: tip
To start the nSPV client for a specific Smart Chain after its data has been added to the coins file, execute the following.
:::
Interacting with the nSPV Client
::: tip
The port in each of these examples is the port on which the nSPV client listens for RPC commands.
For DIC, the port is 7771
. For any other Smart Chain, the port is the rpcport
specified in the coins
file.
This behaviour can be bypassed by setting the -p parameter.
:::
curl Commands Using Named Parameters
Use the example below as a template for creating new curl
commands for any RPCs available in the nSPV API.
curl Command Using the json2.0 Interface
<!--
Sidd: There was a mention below of a "doc", but I am assuming that the doc in question is this document, and that the following example is a good template to use?
gcharang: yes, the doc mentioned is the current document and the parameters' order should be as listed for each method; the example is good -->
When using this format for any RPC that requires parameters (also called "arguments"), provide the parameters in the order they are given in this documentation.
For example, the spentinfo RPC lists txid
as the first parameter and vout
as the second. Observe in the following example how the values in the "params"
key match this order.
Use quotation marks ""
for all strings.
Accessing localhost in the Browser
To access an nSPV client using a browser, create a url that uses http://127.0.0.1:<insert_port>/api/
as the base url, and add the rpc_name/
and any relevant additional parameters/
as additional url directions. See the example below.
Example
-p
Use this parameter at nSPV runtime to set the port on which the nSPV client should listen for RPC commands.
Example
The following command starts the nSPV client for the DIC main chain and listens on port 3000
for RPC commands.
broadcast
broadcast hex
Use this method to broadcast the hex value returned by the spend method.
Arguments
Name | Type | Description |
hex | (string) | the transaction in hex format |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
expected | (string) | the expected transaction id |
broadcast | (string) | the broadcasted transaction id |
retcode | (number) | the return code 0: no error -1,-2,-3: failure -200x: mostly OK, some of the inputs may not be notarized |
type | (string) | the type of the broadcast |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
getinfo
getinfo [hdrheight]
Use this method to get the general information on the state of the blockchain at the moment.
Arguments
Name | Type | Description |
hdrheight | (number, optional) | supplies the height of the block for which the header data is required |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
nSPV | (string) | the mode of nSPV |
address | (string) | the address corresponding to the wifkey |
pubkey | (string) | the pubkey corresponding to the wifkey |
wifexpires | (string) | the time in seconds till the login expires |
height | (number) | the current height of the blockchain |
chaintip | (string) | the blockhash of the last block |
notarization | (json) | a json object containing the notarization details |
notarized_height | (number) | the height of the latest block that has been notarized |
notarized_blockhash | (string) | the blockhash of the latest block that has been notarized |
notarization_txid | (string) | the id of the transaction in which the notarization data is included in the chain being dPoW'ed |
notarization_txidheight | (number) | the height of the block in which the notarization transaction is included |
notarization_desttxid | (string) | the id of the transaction in which the notarization data is included in the chain acting as the data store |
header | (string) | a json object containing the details of the header (of the current block by default / block of height specified by |
height | (number) | the height of the block that has been queried |
blockhash | (string) | the blockhash of the block that has been queried |
hashPrevBlock | (string) | the blockhash of the block before the block that has been queried |
hashMerkleRoot | (string) | the merkleroot of the block that has been queried |
nTime | (number) | a timestamp recording when this block was created |
nBits | (number) | the calculated difficulty target being used for this block |
protocolversion | (string) | the version of the client; helps the nspv client disconnect from nodes that are out of date |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
getnewaddress
getnewaddress
Use this method to create a new address.
Arguments
Name | Type | Description |
(none) |
Response
Name | Type | Description |
wif | (string) | wifkey of the generated address |
address | (string) | the generated address |
pubkey | (string) | pubkey of the generated address |
wifprefix | (number) | prefix of the generated wifkey; depends on the network |
compressed | (number) | whether the wifkey generated is compressed |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
getpeerinfo
getpeerinfo
Use this method to get the information of all peers on the network.
Arguments
Name | Type | Description |
(none) |
Response
Name | Type | Description |
nodeid | (number) | the number given to a node by our instance of the nSPV client |
ipaddress | (string) | the ipaddress of the node |
port | (number) | the p2p port used to connect to this node |
lastping | (number) | the unix time at which this node was last pinged |
time_started_con | (number) | the unix time at which a connection to this node was established |
time_last_request | (number) | the unix time at which a connection was last requested |
services | (number) | (in development) |
missbehavescore | (number) | the score given to this node if the node was misbehaving |
bestknownheight | (number) | the height of the blockchain as best known by this node |
in_sync | (string) | the sync status of the node; |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
hdrsproof
hdrsproof prevheight nextheight
This method scans backwards from the prevheight
until the process encounters a notarization transaction, then forward from nextheight
until the process encounters another notarization transaction.
Then the process finds the notarized blocks corresponding to these two notarization transactions.
Then the process returns all the block headers between these two notarized blocks.
Now that both ends of this segment of blocks are notarized blocks, all block headers in this segment can be validated to see if they link back to each other.
Arguments
Name | Type | Description |
prevheight | (number) | the block number from which headers are required |
nextheight | (number) | the block number to which headers are required |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
prevht | (string) | the height of the first notarized block below the height |
nextht | (string) | the height of the first notarized block above the height |
prevtxid | (string) | the id of the transaction that contains the notarization data of the block of height |
prevtxidht | (string) | the height of the block in which the transaction with id |
prevtxlen | (string) | the length of the transaction with id |
nexttxid | (string) | the id of the transaction that contains the notarization data of the block of height |
nexttxidht | (string) | the height of the block in which the transaction with id |
nexttxlen | (string) | the length of the transaction with id |
numhdrs | (string) | the number of headers being returned |
headers | (string) | a json object containing the details of the header (of the current block by default / block of height specified by |
height | (number) | the height of the block that has been queried |
blockhash | (string) | the blockhash of the block that has been queried |
hashPrevBlock | (string) | the blockhash of the block before the block that has been queried |
hashMerkleRoot | (string) | the merkleroot of the block that has been queried |
nTime | (number) | a timestamp recording when this block was created |
nBits | (number) | the calculated difficulty target being used for this block |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
help
help
This method returns the help output of all available methods.
Arguments
Name | Type | Description |
(none) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
methods | (array of jsons) | an array containing a json object for each method |
method | (string) | name of a method |
fields | (array) | an array conataining the description of parameters expected |
num | (number) | the number of methods available |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
listtransactions
listtransactions [address [isCC [skipcount [filter]]]]
This method returns a list of transactions for an address.
Arguments
Name | Type | Description |
address | (string, optional) | the address for which transactions are to be listed; if not specified, the current active address is used |
isCC | (number, optional) | only return transactions that are related to Antara modules |
skipcount | (number, optional) | skips the specified number of transactions starting from the oldest; always returns the latest transaction |
filter | (number, optional) | (in development) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
txids | (array of jsons) | an array containing jsons that describe the transactions |
height | (number) | the height of the block in which the transaction was included |
txid | (string) | the id of the transaction |
value | (number) | the amount of coins in the vin/vout (inputs and outputs) |
vin/vout | (number) | the index of vin/vout in the transaction |
address | (string) | the address for which the transactions are being returned |
isCC | (number) | whether the address belongs to an Antara module |
height | (number) | the height of the blockchain when this response was returned |
numtxids | (number) | number of vouts/vins being returned |
skipcount | (number) | the number of transactions that have been skipped, starting from the oldest transaction |
filter | (number) | (in development) |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
listunspent
listunspent [address [isCC [skipcount [filter]]]]
Use this method to retrieve all unspent outputs belonging to an address.
Arguments
Name | Type | Description |
address | (string, optional) | the address for which transactions are to be listed; if not specified, the current active address is used |
isCC | (number, optional) | only return transactions that are related to Antara modules |
skipcount | (number, optional) | skips the specified number of transactions starting from the oldest; always returns the latest transaction |
filter | (number, optional) | (in development) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
utxos | (array of jsons) | an array containing jsons that describe the outputs |
height | (number) | the height of the block in which the output was created |
txid | (string) | the id of the transaction in which the output is present |
vout | (number) | the index of the vout (output) in the transaction |
value | (number) | the amount of coins in the vout (output) |
rewards | (number) | the amount of active user rewards claimable by the output |
address | (string) | the address for which the transactions are being returned |
isCC | (number) | whether the address belongs to an Antara module |
height | (number) | the height of the blockchain when this response was returned |
numutxos | (number) | number of vouts(outputs) being returned |
balance | (number) | the total balance available for the address |
rewards | (number) | the total rewards claimable by the address |
skipcount | (number) | the number of utoxs that have been skipped; from the oldest |
filter | (number) | (in development) |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
login
login wif
Use this method to log in to an address using its wifkey.
Arguments
Name | Type | Description |
wif | (string) | the wifkey (wallet import format of the privatekey) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
status | (string) | the time till the expiry of the login |
address | (string) | the address corresponding to the wifkey |
pubkey | (string) | the pubkey corresponding to the wifkey |
wifprefix | (number) | the prefix of the wifkey (indicates the intended network for the wifkey) |
compressed | (boolean) | indicates whether the wifkey is compressed |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
logout
logout
Use this method to log out of the current active address.
Arguments
Name | Type | Description |
(none) |
Response
Name | Type | Description |
result | (string) | whether the command succeeded |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
mempool
mempool address isCC memfunc [txid vout evalcode ccfunc]]]
This method returns the current transactions in the mempool. The various parameters can be used to filter the transactions.
<!--FIXME which args are optional and eachone's use
and values and meanings of memfunc
memfunc (0 all, 1 address recv, 2 txid/vout spent, 3 txid inmempool 4)
gcharang: all the arguments are optional; and they are in development -->
Arguments
Name | Type | Description |
address | (string, optional) | if the transactions should belong to the address |
isCC | (number, optional) | if the transactions should belong to any Antara module |
memfunc | (number, optional) | (in development) |
txid | (string, optional) | (in development) |
vout | (number, optional) | (in development) |
evalcode | (number, optional) | (in development) |
ccfunc | (number, optional) | (in development) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
txids | (array of strings) | the ids of the transactions in the mempool |
address | (string) | the address that was used to filter the mempool |
isCC | (number) | if the transactions returned belong to an Antara Module |
height | (number) | the height of the blockchain when this response was returned |
numtxids | (number) | the number of transaction ids that are being returned |
txid | (string) | (in development) |
vout | (number) | (in development) |
memfunc | (number) | (in development) |
type | (string) | the type of the filter apploed to the mempool |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
notarizations
notarizations height
This method returns the notarization data for a given height.
Arguments
Name | Type | Description |
height | (number) | the height at which notarization data is required |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
prev | (json) | the details of the previous notarization |
notarized_height | (number) | the height of the latest block that has been notarized |
notarized_blockhash | (string) | the blockhash of the latest block that has been notarized |
notarization_txid | (string) | the id of the transaction in which the notarization data is included in the chain being dPoW'ed |
notarization_txidheight | (number) | the height of the block in which the notarization transaction is included |
notarization_desttxid | (string) | the id of the transaction in which the notarization data is included in the chain acting as the data store |
next | (json) | the details of the next notarization |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
spend
spend address amount
<!--FIXME doc retcodes? -->
This method can be used to spend coins from the current active address to any other address.
Arguments
Name | Type | Description |
address | (string) | the address of the recipient |
amount | (number) | the amount to be sent |
Response
Name | Type | Description |
rewards | (string) | the rewards being claimed by this spend transaction |
validated | (string) | (in development) |
tx | (json) | a json object containing details of the transaction |
nVersion | (number) | version of the Indexchain daemon |
vin | (array of jsons) | the inputs being consumed by the transaction |
txid | (string) | the id of the transaction whose input is being spent |
vout | (number) | the output number in the above transaction |
scriptSig | (string) | the redeem script that satisfies the scriptPubkey of the above output |
sequenceid | (number) | the sequence number that has been set |
vout | (array of jsons) | the outputs being created by the transaction |
value | (string) | the value in the output |
scriptPubKey | (string) | the locking script placed on the above value |
nLockTime | (number) | the locktime that has been set |
nExpiryHeight | (number) | the block height after which the transaction will be removed from the mempool if it has not been mined |
valueBalance | (number) | (in development) |
result | (string) | whether the command succeeded |
hex | (string) | the transaction in hex format; this should be broadcast to the network using the broadcast method |
retcodes | (number) | the return codes; an indication of the success or failure of the creation of the transaction |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
spentinfo
spentinfo txid vout
This method returns the spent info of the output specified by the arguments.
Arguments
Name | Type | Description |
txid | (string) | the id of the transaction whose spent info is required |
vout | (number) | the vout number in the above transaction whose spent info is required |
Response
Name | Type | Description |
result | (string) | whether the command succeeded |
txid | (string) | the id of the transaction whose spent info is returned |
vout | (string) | the vout number in the above transaction whose spent info is required |
spentheight | (string) | the block height at which the output has been spent |
spenttxid | (string) | the id of the transaction that spent this output |
spentvini | (string) | the input number of this output in the transaction that spent it |
spenttxlen | (string) | the length of the transaction that spent this output |
spenttxprooflen | (string) | the length of proof of the transaction that spent this output |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
stop
stop
Stops the nSPV instance associated with the port specified in the curl command.
Arguments
Name | Type | Description |
(none) |
Response
Name | Type | Description |
result | (string) | whether the command was successful |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
txproof
txproof txid vout [height]
This method is an internal function used by the gettransaction method.
Arguments
Name | Type | Description |
txid | (string) | the id of the transaction whose proof is requested |
vout | (number) | the number of the output in the above transaction |
height | (number, optional) |
Response
Name | Type | Description |
txid | (string) | the id of the transaction whose proof is returned |
height | (string) | the height at which the proof of the transaction is returned |
txlen | (string) | the length of the transaction |
txprooflen | (string) | the length of the proof for the transaction |
lastpeer | (string) | the last known peer |
📌 Examples
Command
<collapse-text hidden title="Response">
</collapse-text>
Last updated