Remove Sumtree References and disambiguate some naming (#747)
* start of renamathon * api renaming * Rename UTXO-Output to lessen ambiguity * compile warning * compile error * readme fix * remove file commit in error
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2016 The Grin Developers
|
||||
// Copyright 2018 The Grin Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
||||
+45
-45
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017 The Grin Developers
|
||||
// Copyright 2018 The Grin Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -58,15 +58,15 @@ impl Handler for IndexHandler {
|
||||
}
|
||||
|
||||
// Supports retrieval of multiple outputs in a single request -
|
||||
// GET /v1/chain/utxos/byids?id=xxx,yyy,zzz
|
||||
// GET /v1/chain/utxos/byids?id=xxx&id=yyy&id=zzz
|
||||
// GET /v1/chain/utxos/byheight?start_height=101&end_height=200
|
||||
struct UtxoHandler {
|
||||
// GET /v1/chain/outputs/byids?id=xxx,yyy,zzz
|
||||
// GET /v1/chain/outputs/byids?id=xxx&id=yyy&id=zzz
|
||||
// GET /v1/chain/outputs/byheight?start_height=101&end_height=200
|
||||
struct OutputHandler {
|
||||
chain: Weak<chain::Chain>,
|
||||
}
|
||||
|
||||
impl UtxoHandler {
|
||||
fn get_utxo(&self, id: &str) -> Result<Utxo, Error> {
|
||||
impl OutputHandler {
|
||||
fn get_output(&self, id: &str) -> Result<Output, Error> {
|
||||
let c = util::from_hex(String::from(id))
|
||||
.map_err(|_| Error::Argument(format!("Not a valid commitment: {}", id)))?;
|
||||
let commit = Commitment::from_vec(c);
|
||||
@@ -82,13 +82,13 @@ impl UtxoHandler {
|
||||
|
||||
for x in outputs.iter() {
|
||||
if let Ok(_) = w(&self.chain).is_unspent(&x) {
|
||||
return Ok(Utxo::new(&commit));
|
||||
return Ok(Output::new(&commit));
|
||||
}
|
||||
}
|
||||
Err(Error::NotFound)
|
||||
}
|
||||
|
||||
fn utxos_by_ids(&self, req: &mut Request) -> Vec<Utxo> {
|
||||
fn outputs_by_ids(&self, req: &mut Request) -> Vec<Output> {
|
||||
let mut commitments: Vec<&str> = vec![];
|
||||
if let Ok(params) = req.get_ref::<UrlEncodedQuery>() {
|
||||
if let Some(ids) = params.get("id") {
|
||||
@@ -100,15 +100,15 @@ impl UtxoHandler {
|
||||
}
|
||||
}
|
||||
|
||||
debug!(LOGGER, "utxos_by_ids: {:?}", commitments);
|
||||
debug!(LOGGER, "outputs_by_ids: {:?}", commitments);
|
||||
|
||||
let mut utxos: Vec<Utxo> = vec![];
|
||||
let mut outputs: Vec<Output> = vec![];
|
||||
for x in commitments {
|
||||
if let Ok(utxo) = self.get_utxo(x) {
|
||||
utxos.push(utxo);
|
||||
if let Ok(output) = self.get_output(x) {
|
||||
outputs.push(output);
|
||||
}
|
||||
}
|
||||
utxos
|
||||
outputs
|
||||
}
|
||||
|
||||
fn outputs_at_height(
|
||||
@@ -186,7 +186,7 @@ impl UtxoHandler {
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler for UtxoHandler {
|
||||
impl Handler for OutputHandler {
|
||||
fn handle(&self, req: &mut Request) -> IronResult<Response> {
|
||||
let url = req.url.clone();
|
||||
let mut path_elems = url.path();
|
||||
@@ -194,7 +194,7 @@ impl Handler for UtxoHandler {
|
||||
path_elems.pop();
|
||||
}
|
||||
match *path_elems.last().unwrap() {
|
||||
"byids" => json_response(&self.utxos_by_ids(req)),
|
||||
"byids" => json_response(&self.outputs_by_ids(req)),
|
||||
"byheight" => json_response(&self.outputs_block_batch(req)),
|
||||
_ => Ok(Response::with((status::BadRequest, ""))),
|
||||
}
|
||||
@@ -202,40 +202,40 @@ impl Handler for UtxoHandler {
|
||||
}
|
||||
|
||||
// Sum tree handler. Retrieve the roots:
|
||||
// GET /v1/pmmrtrees/roots
|
||||
// GET /v1/txhashset/roots
|
||||
//
|
||||
// Last inserted nodes::
|
||||
// GET /v1/pmmrtrees/lastutxos (gets last 10)
|
||||
// GET /v1/pmmrtrees/lastutxos?n=5
|
||||
// GET /v1/pmmrtrees/lastrangeproofs
|
||||
// GET /v1/pmmrtrees/lastkernels
|
||||
struct SumTreeHandler {
|
||||
// GET /v1/txhashset/lastoutputs (gets last 10)
|
||||
// GET /v1/txhashset/lastoutputs?n=5
|
||||
// GET /v1/txhashset/lastrangeproofs
|
||||
// GET /v1/txhashset/lastkernels
|
||||
struct TxHashSetHandler {
|
||||
chain: Weak<chain::Chain>,
|
||||
}
|
||||
|
||||
impl SumTreeHandler {
|
||||
impl TxHashSetHandler {
|
||||
// gets roots
|
||||
fn get_roots(&self) -> SumTrees {
|
||||
SumTrees::from_head(w(&self.chain))
|
||||
fn get_roots(&self) -> TxHashSet {
|
||||
TxHashSet::from_head(w(&self.chain))
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_utxo(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_utxo(w(&self.chain), distance)
|
||||
// gets last n outputs inserted in to the tree
|
||||
fn get_last_n_output(&self, distance: u64) -> Vec<TxHashSetNode> {
|
||||
TxHashSetNode::get_last_n_output(w(&self.chain), distance)
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_rangeproof(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_rangeproof(w(&self.chain), distance)
|
||||
// gets last n outputs inserted in to the tree
|
||||
fn get_last_n_rangeproof(&self, distance: u64) -> Vec<TxHashSetNode> {
|
||||
TxHashSetNode::get_last_n_rangeproof(w(&self.chain), distance)
|
||||
}
|
||||
|
||||
// gets last n utxos inserted in to the tree
|
||||
fn get_last_n_kernel(&self, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
PmmrTreeNode::get_last_n_kernel(w(&self.chain), distance)
|
||||
// gets last n outputs inserted in to the tree
|
||||
fn get_last_n_kernel(&self, distance: u64) -> Vec<TxHashSetNode> {
|
||||
TxHashSetNode::get_last_n_kernel(w(&self.chain), distance)
|
||||
}
|
||||
}
|
||||
|
||||
impl Handler for SumTreeHandler {
|
||||
impl Handler for TxHashSetHandler {
|
||||
fn handle(&self, req: &mut Request) -> IronResult<Response> {
|
||||
let url = req.url.clone();
|
||||
let mut path_elems = url.path();
|
||||
@@ -255,7 +255,7 @@ impl Handler for SumTreeHandler {
|
||||
}
|
||||
match *path_elems.last().unwrap() {
|
||||
"roots" => json_response_pretty(&self.get_roots()),
|
||||
"lastutxos" => json_response_pretty(&self.get_last_n_utxo(last_n)),
|
||||
"lastoutputs" => json_response_pretty(&self.get_last_n_output(last_n)),
|
||||
"lastrangeproofs" => json_response_pretty(&self.get_last_n_rangeproof(last_n)),
|
||||
"lastkernels" => json_response_pretty(&self.get_last_n_kernel(last_n)),
|
||||
_ => Ok(Response::with((status::BadRequest, ""))),
|
||||
@@ -572,7 +572,7 @@ pub fn start_rest_apis<T>(
|
||||
.name("apis".to_string())
|
||||
.spawn(move || {
|
||||
// build handlers and register them under the appropriate endpoint
|
||||
let utxo_handler = UtxoHandler {
|
||||
let output_handler = OutputHandler {
|
||||
chain: chain.clone(),
|
||||
};
|
||||
let block_handler = BlockHandler {
|
||||
@@ -585,7 +585,7 @@ pub fn start_rest_apis<T>(
|
||||
chain: chain.clone(),
|
||||
peers: peers.clone(),
|
||||
};
|
||||
let sumtree_handler = SumTreeHandler {
|
||||
let txhashset_handler = TxHashSetHandler {
|
||||
chain: chain.clone(),
|
||||
};
|
||||
let pool_info_handler = PoolInfoHandler {
|
||||
@@ -610,12 +610,12 @@ pub fn start_rest_apis<T>(
|
||||
let route_list = vec![
|
||||
"get blocks".to_string(),
|
||||
"get chain".to_string(),
|
||||
"get chain/utxos".to_string(),
|
||||
"get chain/outputs".to_string(),
|
||||
"get status".to_string(),
|
||||
"get pmmrtrees/roots".to_string(),
|
||||
"get pmmrtrees/lastutxos?n=10".to_string(),
|
||||
"get pmmrtrees/lastrangeproofs".to_string(),
|
||||
"get pmmrtrees/lastkernels".to_string(),
|
||||
"get txhashset/roots".to_string(),
|
||||
"get txhashset/lastoutputs?n=10".to_string(),
|
||||
"get txhashset/lastrangeproofs".to_string(),
|
||||
"get txhashset/lastkernels".to_string(),
|
||||
"get pool".to_string(),
|
||||
"post pool/push".to_string(),
|
||||
"post peers/a.b.c.d:p/ban".to_string(),
|
||||
@@ -631,9 +631,9 @@ pub fn start_rest_apis<T>(
|
||||
index: get "/" => index_handler,
|
||||
blocks: get "/blocks/*" => block_handler,
|
||||
chain_tip: get "/chain" => chain_tip_handler,
|
||||
chain_utxos: get "/chain/utxos/*" => utxo_handler,
|
||||
chain_outputs: get "/chain/outputs/*" => output_handler,
|
||||
status: get "/status" => status_handler,
|
||||
sumtree_roots: get "/pmmrtrees/*" => sumtree_handler,
|
||||
txhashset_roots: get "/txhashset/*" => txhashset_handler,
|
||||
pool_info: get "/pool" => pool_info_handler,
|
||||
pool_push: post "/pool/push" => pool_push_handler,
|
||||
peers_all: get "/peers/all" => peers_all_handler,
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2016 The Grin Developers
|
||||
// Copyright 2018 The Grin Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Copyright 2016 The Grin Developers
|
||||
// Copyright 2018 The Grin Developers
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
|
||||
+31
-31
@@ -84,64 +84,64 @@ impl Status {
|
||||
}
|
||||
}
|
||||
|
||||
/// Sumtrees
|
||||
/// TxHashSet
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct SumTrees {
|
||||
/// UTXO Root Hash
|
||||
pub utxo_root_hash: String,
|
||||
pub struct TxHashSet {
|
||||
/// Output Root Hash
|
||||
pub output_root_hash: String,
|
||||
// Rangeproof root hash
|
||||
pub range_proof_root_hash: String,
|
||||
// Kernel set root hash
|
||||
pub kernel_root_hash: String,
|
||||
}
|
||||
|
||||
impl SumTrees {
|
||||
pub fn from_head(head: Arc<chain::Chain>) -> SumTrees {
|
||||
let roots = head.get_sumtree_roots();
|
||||
SumTrees {
|
||||
utxo_root_hash: roots.0.to_hex(),
|
||||
impl TxHashSet {
|
||||
pub fn from_head(head: Arc<chain::Chain>) -> TxHashSet {
|
||||
let roots = head.get_txhashset_roots();
|
||||
TxHashSet {
|
||||
output_root_hash: roots.0.to_hex(),
|
||||
range_proof_root_hash: roots.1.to_hex(),
|
||||
kernel_root_hash: roots.2.to_hex(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Wrapper around a list of sumtree nodes, so it can be
|
||||
/// Wrapper around a list of txhashset nodes, so it can be
|
||||
/// presented properly via json
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct PmmrTreeNode {
|
||||
pub struct TxHashSetNode {
|
||||
// The hash
|
||||
pub hash: String,
|
||||
}
|
||||
|
||||
impl PmmrTreeNode {
|
||||
pub fn get_last_n_utxo(chain: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
impl TxHashSetNode {
|
||||
pub fn get_last_n_output(chain: Arc<chain::Chain>, distance: u64) -> Vec<TxHashSetNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = chain.get_last_n_utxo(distance);
|
||||
let last_n = chain.get_last_n_output(distance);
|
||||
for x in last_n {
|
||||
return_vec.push(PmmrTreeNode {
|
||||
return_vec.push(TxHashSetNode {
|
||||
hash: util::to_hex(x.0.to_vec()),
|
||||
});
|
||||
}
|
||||
return_vec
|
||||
}
|
||||
|
||||
pub fn get_last_n_rangeproof(head: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
pub fn get_last_n_rangeproof(head: Arc<chain::Chain>, distance: u64) -> Vec<TxHashSetNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = head.get_last_n_rangeproof(distance);
|
||||
for elem in last_n {
|
||||
return_vec.push(PmmrTreeNode {
|
||||
return_vec.push(TxHashSetNode {
|
||||
hash: util::to_hex(elem.0.to_vec()),
|
||||
});
|
||||
}
|
||||
return_vec
|
||||
}
|
||||
|
||||
pub fn get_last_n_kernel(head: Arc<chain::Chain>, distance: u64) -> Vec<PmmrTreeNode> {
|
||||
pub fn get_last_n_kernel(head: Arc<chain::Chain>, distance: u64) -> Vec<TxHashSetNode> {
|
||||
let mut return_vec = Vec::new();
|
||||
let last_n = head.get_last_n_kernel(distance);
|
||||
for elem in last_n {
|
||||
return_vec.push(PmmrTreeNode {
|
||||
return_vec.push(TxHashSetNode {
|
||||
hash: util::to_hex(elem.0.to_vec()),
|
||||
});
|
||||
}
|
||||
@@ -156,14 +156,14 @@ pub enum OutputType {
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Utxo {
|
||||
pub struct Output {
|
||||
/// The output commitment representing the amount
|
||||
pub commit: PrintableCommitment,
|
||||
}
|
||||
|
||||
impl Utxo {
|
||||
pub fn new(commit: &pedersen::Commitment) -> Utxo {
|
||||
Utxo {
|
||||
impl Output {
|
||||
pub fn new(commit: &pedersen::Commitment) -> Output {
|
||||
Output {
|
||||
commit: PrintableCommitment(commit.clone()),
|
||||
}
|
||||
}
|
||||
@@ -503,11 +503,11 @@ pub struct BlockHeaderPrintable {
|
||||
pub previous: String,
|
||||
/// rfc3339 timestamp at which the block was built.
|
||||
pub timestamp: String,
|
||||
/// Merklish root of all the commitments in the UTXO set
|
||||
pub utxo_root: String,
|
||||
/// Merklish root of all range proofs in the UTXO set
|
||||
/// Merklish root of all the commitments in the TxHashSet
|
||||
pub output_root: String,
|
||||
/// Merklish root of all range proofs in the TxHashSet
|
||||
pub range_proof_root: String,
|
||||
/// Merklish root of all transaction kernels in the UTXO set
|
||||
/// Merklish root of all transaction kernels in the TxHashSet
|
||||
pub kernel_root: String,
|
||||
/// Nonce increment used to mine this block.
|
||||
pub nonce: u64,
|
||||
@@ -525,7 +525,7 @@ impl BlockHeaderPrintable {
|
||||
height: h.height,
|
||||
previous: util::to_hex(h.previous.to_vec()),
|
||||
timestamp: h.timestamp.rfc3339().to_string(),
|
||||
utxo_root: util::to_hex(h.utxo_root.to_vec()),
|
||||
output_root: util::to_hex(h.output_root.to_vec()),
|
||||
range_proof_root: util::to_hex(h.range_proof_root.to_vec()),
|
||||
kernel_root: util::to_hex(h.kernel_root.to_vec()),
|
||||
nonce: h.nonce,
|
||||
@@ -643,7 +643,7 @@ mod test {
|
||||
use serde_json;
|
||||
|
||||
#[test]
|
||||
fn serialize_output() {
|
||||
fn serialize_output_printable() {
|
||||
let hex_output =
|
||||
"{\
|
||||
\"output_type\":\"Coinbase\",\
|
||||
@@ -660,10 +660,10 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialize_utxo() {
|
||||
fn serialize_output() {
|
||||
let hex_commit =
|
||||
"{\"commit\":\"083eafae5d61a85ab07b12e1a51b3918d8e6de11fc6cde641d54af53608aa77b9f\"}";
|
||||
let deserialized: Utxo = serde_json::from_str(&hex_commit).unwrap();
|
||||
let deserialized: Output = serde_json::from_str(&hex_commit).unwrap();
|
||||
let serialized = serde_json::to_string(&deserialized).unwrap();
|
||||
assert_eq!(serialized, hex_commit);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user