Skip to content
Snippets Groups Projects
Commit 9e7bd7fd authored by jm's avatar jm
Browse files

[feat] gva: add previous_hash dividend field

parent 641a25b5
No related tags found
No related merge requests found
......@@ -97,6 +97,8 @@ pub trait BlockDocumentTrait {
fn unit_base(&self) -> usize;
/// Get issuers_frame_var
fn issuers_frame_var(&self) -> isize;
/// Get dividend
fn dividend(&self) -> Option<usize>;
}
impl BlockDocumentTrait for BlockDocument {
......@@ -238,6 +240,12 @@ impl BlockDocumentTrait for BlockDocument {
BlockDocument::V10(block) => block.issuers_frame_var(),
}
}
#[inline]
fn dividend(&self) -> Option<usize> {
match self {
BlockDocument::V10(block) => block.dividend(),
}
}
}
impl Document for BlockDocument {
......
......@@ -368,6 +368,9 @@ Transactions:{transactions}
fn issuers_frame_var(&self) -> isize {
self.issuers_frame_var
}
fn dividend(&self) -> Option<usize> {
self.dividend
}
}
impl Document for BlockDocumentV10 {
......
......@@ -91,6 +91,8 @@ type Block {
unitBase: Int!
issuersFrame: Int!
issuersFrameVar: Int!
previousHash: String
dividend: Int
}
#################################
......
......@@ -40,6 +40,8 @@ pub struct Block {
unit_base: i32,
issuers_frame: i32,
issuers_frame_var: i32,
previous_hash: Option<String>,
dividend: Option<i32>,
}
impl Block {
......@@ -75,6 +77,8 @@ impl Block {
unit_base: block_db.block.unit_base() as i32,
issuers_frame: block_db.block.current_frame_size() as i32,
issuers_frame_var: block_db.block.issuers_frame_var() as i32,
previous_hash: block_db.block.previous_hash().map(|hash| hash.to_string()),
dividend: block_db.block.dividend().map(|dividend| dividend as i32),
})
}
}
......@@ -138,4 +142,15 @@ impl super::super::BlockFields for Block {
fn field_issuers_frame_var(&self, _executor: &Executor<'_, QueryContext>) -> FieldResult<&i32> {
Ok(&self.issuers_frame_var)
}
#[inline]
fn field_previous_hash(
&self,
_executor: &Executor<'_, QueryContext>,
) -> FieldResult<&Option<String>> {
Ok(&self.previous_hash)
}
#[inline]
fn field_dividend(&self, _executor: &Executor<'_, QueryContext>) -> FieldResult<&Option<i32>> {
Ok(&self.dividend)
}
}
......@@ -73,6 +73,8 @@ mod tests {
block.pow_min = 70;
block.issuers_frame = 125;
block.issuers_frame_var = 3;
block.previous_hash = Some(hash('C'));
block.dividend = Some(1032);
Ok(Some(BlockDb {
block: BlockDocument::V10(block),
expire_certs: None,
......@@ -102,7 +104,7 @@ mod tests {
tests::test_gql_query(
schema,
"{ block(number: 42) { commonTime, currency, hash, issuer, issuerName, issuersCount, number, powMin, version, issuersFrame, issuersFrameVar } }",
"{ block(number: 42) { commonTime, currency, hash, issuer, issuerName, issuersCount, number, powMin, version, issuersFrame, issuersFrameVar, previousHash, dividend} }",
json!({
"data": {
"block": {
......@@ -117,6 +119,8 @@ mod tests {
"version": 10,
"issuersFrame": 125,
"issuersFrameVar": 3,
"previousHash": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
"dividend": 1032,
}
}
}),
......
......@@ -60,6 +60,10 @@ mod tests {
current_block.pow_min = 70;
current_block.members_count = 59;
current_block.unit_base = 1;
current_block.issuers_frame = 155;
current_block.issuers_frame_var = -2;
current_block.previous_hash = Some(hash('C'));
current_block.dividend = Some(1072);
Ok(Some(BlockDb {
block: BlockDocument::V10(current_block),
expire_certs: None,
......@@ -75,7 +79,7 @@ mod tests {
tests::test_gql_query(
schema,
"{ current { commonTime, currency, hash, issuer, issuerName, membersCount, number, powMin, version, unitBase } }",
"{ current { commonTime, currency, hash, issuer, issuerName, membersCount, number, powMin, version, unitBase, issuersFrameVar, issuersFrame, dividend, previousHash} }",
json!({
"data": {
"current": {
......@@ -89,6 +93,10 @@ mod tests {
"powMin": 70,
"version": 10,
"unitBase": 1,
"issuersFrameVar": -2,
"issuersFrame": 155,
"dividend": 1072,
"previousHash": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
}
}
}),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment