Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update some RPCs to show more useful data #82

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ impl<PersistedState: ChainStore> BlockchainInterface for ChainState<PersistedSta
fn is_in_idb(&self) -> bool {
self.inner.read().ibd
}
fn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error> {
self.get_disk_block_header(hash)
.map(|header| header.height())
}

fn get_block_hash(&self, height: u32) -> Result<bitcoin::BlockHash, Self::Error> {
let inner = self.inner.read();
Expand Down
3 changes: 3 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ pub trait BlockchainInterface {
fn get_validation_index(&self) -> Result<u32, Self::Error>;
/// Triggers a rescan, downloading (but not validating) all blocks in [start_height:tip]
fn rescan(&self, start_height: u32) -> Result<(), Self::Error>;
/// Returns where we are in the rescan
fn get_rescan_index(&self) -> Option<u32>;
/// Returns the height of a block, given it's hash
fn get_block_height(&self, hash: &BlockHash) -> Result<Option<u32>, Self::Error>;
}
/// [UpdatableChainstate] is a contract that a is expected from a chainstate
/// implementation, that wishes to be updated. Using those methods, a backend like the p2p-node,
Expand Down
203 changes: 118 additions & 85 deletions crates/floresta-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,141 +25,179 @@ This command takes no params and returns some useful data about the current acti
**Args**: None

**Return**
```json
{
"best_block": "A hash of the latest block we know about",
"height": "The position of our current best known block",
"ibd": "Whether we are on Initial Block Download"
}
```

`best_block`: The best block we have headers for
`chain`: The name of the current active network(eg: bitcoin, testnet, regtest)
`difficulty`: Current network difficulty
`height`: The height of the best block we have headers for
`ibd`: Whether we are currently in initial block download
`latest_block_time`: The time in which the latest block was mined
`latest_work`: The work of the latest block (e.g the amount of hashes needed to mine it, on average)
`leaf_count`: The amount of leaves in our current forest state
`progress`: The percentage of blocks we have validated so far
`root_count`: The amount of roots in our current forest state
`root_hashes`: The hashes of the roots in our current forest state
`validated`: The amount of blocks we have validated so far
`verification_progress`: The percentage of blocks we have verified so far

### getblockhash

Returns the block hash associated with a given height
**Args**
```
height: A numerical identifier for a block
```

`height`: A numerical identifier for a block

**Return**
```
block_hash: A string containing a hex-encoded block hash
```

`block_hash`: A string containing a hex-encoded block hash


### gettxout

Returns a cached transaction output. The output itself doesn't have to be ours. But the transaction containing it should be cached by our internal wallet.
**Args**
```
tx_id: A transaction id
vout: A index for the desired output
```

`tx_id`: A transaction id
`vout`: A index for the desired output

**Returns**
```json
{
"value": "The amount of satoshis in this output",
"spk": "The redeem script for this output"
}
```

`value`: The amount of satoshis in this output,
`spk`: The redeem script for this output


### getrawtransaction

Returns a transaction data, given its id. The transaction itself doesn't have to be ours. But it should be cached by our internal wallet or in the mempool.

**Args**
```
tx_id: The id of a transaction
```

`tx_id`: The id of a transaction

**Returns**
```json
{
"tx": "A object describing a transaction"
}
```

`blockhash`: The hash of the block containing this transaction, if it is in a block
`blocktime`: Time when the block containing this transaction was mined, if it is in a block
`confirmations`: The amount of confirmations this transaction has, if it is in a block
`hash`: The hash of this transaction, a.k.a wtxid
`hex`: The hex-encoded transaction
`in_active_chain`: Whether this transaction is in the active chain
`locktime`: The locktime value of this transaction.
`size`: The size of this transaction in bytes.
`time`: The time when this transaction was mined, if it is in a block
`txid`: The id of this transaction. Only for witness transactions, this is `different` from the wtxid
`version`: The version of this transaction
`vin`: A vector of inputs
`script_sig`: The script signature for this input
`asm`: The disassembled script signature
`hex`: Raw hex-encoded script signature
`sequence`: The nSequence value for this input
`txid`: The id of the transaction containing the output we are spending
`vout`: The index of the output we are spending
`witness`: A vector of witness data
`vout`: A vector of outputs
`n`: The index of this output
`script_pub_key`: The script pubkey for this output
`address`: The address this output pays to, if it's a standard output
`asm`: The disassembled script pubkey
`hex`: Raw hex-encoded script pubkey
`req_sigs`: The amount of signatures required to spend this output (Deprecated)
`type`: The type of this output (e.g pubkeyhash, scripthash, etc)
`value`: The amount of satoshis in this output
`vsize`: The size of this transaction, in virtual bytes
`weight`: The weight of this transaction

### rescan

Tells our node to rescan blocks. This will make our node download all blocks all over again, which may be network intensive.
This rpc is useful if you add another address, descriptor or xpub to our wallet, and you know it have historical transactions that are not indexed yet.

**Args**
```
height: The height we should start
```

`height`: The height we should start

**Return**
```
success: Whether we successfully started rescanning
```

`success`: Whether we successfully started rescanning


### sendrawtransaction

Submits a transaction to the network

**Args**
```
tx_hex: A hex-encoded transaction
```

`tx_hex`: A hex-encoded transaction

**Return**
```
tx_id: The transaction id if we succeed
```

`tx_id`: The transaction id if we succeed


### getblockheader

Returns the header of a block, giving its hash

**Args**
```
block_hash: The id of a block
```

`block_hash`: The id of a block

**Return**:
```json
{
"block_header": {
"bits": "A compact representation of the block target",
"merkle_root": "The root of a tree formed by all transactions in this block",
"nonce": "The nonce used to mine this block",
"prev_blockhash": "The hash of this block's ancestor",
"time": "The time in which this block was created",
"version": "This block's version"
}
}
```

`bits`: A compact representation of the block target
`merkle_root`: The root of a tree formed by all transactions in this block
`nonce`: The nonce used to mine this block
`prev_blockhash`: The hash of this block's ancestor
`time`: The time in which this block was created
`version`: This block's version

### loaddescriptor

Tells our wallet to follow this new descriptor. Optionally, whether we should rescan the blockchain if there's any historical transaction associated with this descriptor.

**Args**
```
descriptor: A output descriptor
```

`descriptor`: A output descriptor

**Return**
```
status: Whether we succeed loading this descriptor
```

`status`: Whether we succeed loading this descriptor

### getroots

Returns the roots of our current forest state

**Args**: None
**Return**
```
roots: A vec of hashes
```

`roots`: A vec of hashes

### getblock

Returns a full block, given its hash. Notice that this rpc will cause a actual network request to our node, so it may be slow, and if used too often, may cause more network usage.

**Args**
```
block_hash: The hash of a block
```
**Return**
```json
{
"block": "A block object"
}
```

`block_hash`: The hash of a block
`bits`: A compact representation of the block target
`chainwork`: The combined work of all blocks in this blockchain
`confirmations`: The amount of confirmations this block has
`difficulty`: This block's difficulty
`hash`: This block's hash
`height`: This block's height
`mediantime`: The median of the timestamps of the last 11 blocks
`merkleroot`: The root of a tree formed by all transactions in this block
`n_tx`: The amount of transactions in this block
`nextblockhash`": The hash of the next block, if any
`nonce`: The nonce used to mine this block
`previousblockhash`": The hash of this block's ancestor
`size`: The size of this block in bytes
`strippedsize`: The size of this block in bytes, excluding witness data
`time`: The time in which this block was created
`tx`: A txid vector of transactions in this block
`version`: This block's version
`versionHex`: This block's version, in hex
`weight`: The weight of this block

### getpeerinfo

Expand All @@ -168,12 +206,7 @@ Returns a list of peers connected to our node, and some useful information about
**Args**: None

**Returns**
```json
[
{
"address": "This peer's network address",
"services": "The services this peer announces as supported",
"user_agent": "A string representing this peer's software",
}
]
```
`peers`: A vector of peers connected to our node
`address`: This peer's network address
`services`: The services this peer announces as supported
`user_agent`: A string representing this peer's software
77 changes: 77 additions & 0 deletions florestad/src/json_rpc/res.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,83 @@ pub struct GetBlockchainInfoRes {
pub height: u32,
pub ibd: bool,
pub validated: u32,
pub latest_work: String,
pub latest_block_time: u32,
pub leaf_count: u32,
pub root_count: u32,
pub root_hashes: Vec<String>,
pub chain: String,
pub progress: f32,
pub difficulty: u64,
}
#[derive(Deserialize, Serialize)]
pub struct RawTxJson {
pub in_active_chain: bool,
pub hex: String,
pub txid: String,
pub hash: String,
pub size: u32,
pub vsize: u32,
pub weight: u32,
pub version: u32,
pub locktime: u32,
pub vin: Vec<TxInJson>,
pub vout: Vec<TxOutJson>,
pub blockhash: String,
pub confirmations: u32,
pub blocktime: u32,
pub time: u32,
}
#[derive(Deserialize, Serialize)]
pub struct TxOutJson {
pub value: u64,
pub n: u32,
pub script_pub_key: ScriptPubKeyJson,
}
#[derive(Deserialize, Serialize)]
pub struct ScriptPubKeyJson {
pub asm: String,
pub hex: String,
pub req_sigs: u32,
#[serde(rename = "type")]
pub type_: String,
pub address: String,
}
#[derive(Deserialize, Serialize)]
pub struct TxInJson {
pub txid: String,
pub vout: u32,
pub script_sig: ScriptSigJson,
pub sequence: u32,
pub witness: Vec<String>,
}
#[derive(Deserialize, Serialize)]
pub struct ScriptSigJson {
pub asm: String,
pub hex: String,
}
#[derive(Deserialize, Serialize)]
pub struct BlockJson {
pub hash: String,
pub confirmations: u32,
pub strippedsize: usize,
pub size: usize,
pub weight: usize,
pub height: u32,
pub version: i32,
#[serde(rename = "versionHex")]
pub version_hex: String,
pub merkleroot: String,
pub tx: Vec<String>,
pub time: u32,
pub mediantime: u32,
pub nonce: u32,
pub bits: String,
pub difficulty: u64,
pub chainwork: String,
pub n_tx: usize,
pub previousblockhash: String,
pub nextblockhash: Option<String>,
}

#[derive(Debug)]
Expand Down
Loading
Loading