Skip to content

Commit

Permalink
chore: merge develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelcr committed Oct 22, 2024
2 parents 5a6a791 + f48cda5 commit a47b3d2
Show file tree
Hide file tree
Showing 22 changed files with 854 additions and 250 deletions.
15 changes: 14 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@
"cwd": "${workspaceFolder}",
"preLaunchTask": "redis:start",
"postDebugTask": "redis:stop"
}
},
{
"type": "node",
"request": "launch",
"name": "test: typescript client",
"localRoot": "${workspaceFolder}/components/client/typescript",
"program": "${workspaceFolder}/components/client/typescript/node_modules/jest/bin/jest",
"args": [
"--runInBand",
"--no-cache",
],
"outputCapture": "std",
"console": "integratedTerminal",
},
]
}
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::scan::stacks::{Record, RecordKind};
use crate::service::tests::helpers::mock_bitcoin_rpc::TipData;
use chainhook_sdk::indexer::bitcoin::NewBitcoinBlock;
use chainhook_sdk::indexer::stacks::{NewBlock, NewEvent, NewTransaction};
use chainhook_sdk::indexer::stacks::{NewBlock, NewEvent, NewTransaction, RewardSet, RewardSetSigner};
use chainhook_sdk::types::{
FTBurnEventData, FTMintEventData, FTTransferEventData, NFTBurnEventData, NFTMintEventData,
NFTTransferEventData, STXBurnEventData, STXLockEventData, STXMintEventData,
Expand Down Expand Up @@ -260,6 +260,26 @@ pub fn create_stacks_new_block(
transactions: (0..4).map(create_stacks_new_transaction).collect(),
events,
matured_miner_rewards: vec![],
block_time: Some(12345),
signer_bitvec: Some("000800000001ff".to_owned()),
signer_signature: Some(vec!["1234".to_owned(), "2345".to_owned()]),
cycle_number: Some(1),
reward_set: Some(RewardSet {
pox_ustx_threshold: "50000".to_owned(),
rewarded_addresses: vec![],
signers: Some(vec![
RewardSetSigner {
signing_key: "0123".to_owned(),
weight: 123,
stacked_amt: "555555".to_owned(),
},
RewardSetSigner {
signing_key: "2345".to_owned(),
weight: 234,
stacked_amt: "6677777".to_owned(),
},
]),
}),
}
}

Expand Down
1 change: 1 addition & 0 deletions components/chainhook-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ prometheus = "0.13.3"
chainhook-types = { path = "../chainhook-types-rs" }

[dev-dependencies]
assert-json-diff = "2.0.2"
test-case = "3.1.0"

[features]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -96,7 +101,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -177,7 +187,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -259,7 +274,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -340,7 +360,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -423,7 +448,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -505,7 +535,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -587,7 +622,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -670,7 +710,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -752,7 +797,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -834,7 +884,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -916,7 +971,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -998,7 +1058,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down Expand Up @@ -1090,7 +1155,12 @@
"pox_cycle_index": 415,
"pox_cycle_length": 1050,
"pox_cycle_position": 1033,
"stacks_block_hash": "0x"
"stacks_block_hash": "0x",
"block_time": null,
"cycle_number": null,
"reward_set": null,
"signer_bitvec": null,
"signer_signature": null
},
"parent_block_identifier": {
"hash": "0x",
Expand Down
9 changes: 4 additions & 5 deletions components/chainhook-sdk/src/chainhooks/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::{
},
utils::AbstractStacksBlock,
};
use assert_json_diff::assert_json_eq;
use chainhook_types::{
StacksBlockUpdate, StacksChainEvent, StacksChainUpdatedWithBlocksData, StacksNetwork,
StacksTransactionData, StacksTransactionEvent, StacksTransactionEventPayload,
Expand Down Expand Up @@ -823,11 +824,9 @@ fn test_stacks_hook_action_file_append() {
handle_stacks_hook_action(trigger, &proofs, &EventObserverConfig::default(), &ctx).unwrap();
if let StacksChainhookOccurrence::File(path, bytes) = occurrence {
assert_eq!(path, "./".to_string());
let json: JsonValue = serde_json::from_slice(&bytes).unwrap();
let obj = json.as_object().unwrap();
let actual = serde_json::to_string_pretty(obj).unwrap();
let expected = get_expected_occurrence();
assert_eq!(expected, actual);
let actual: JsonValue = serde_json::from_slice(&bytes).unwrap();
let expected: JsonValue = serde_json::from_str(&get_expected_occurrence()).unwrap();
assert_json_eq!(expected, actual);
} else {
panic!("wrong occurrence type");
}
Expand Down
53 changes: 53 additions & 0 deletions components/chainhook-sdk/src/indexer/stacks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,36 @@ pub struct NewBlock {
pub transactions: Vec<NewTransaction>,
pub events: Vec<NewEvent>,
pub matured_miner_rewards: Vec<MaturedMinerReward>,

#[serde(skip_serializing_if = "Option::is_none")]
pub block_time: Option<u64>,

#[serde(skip_serializing_if = "Option::is_none")]
pub signer_bitvec: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
pub signer_signature: Option<Vec<String>>,

#[serde(skip_serializing_if = "Option::is_none")]
pub cycle_number: Option<u64>,

#[serde(skip_serializing_if = "Option::is_none")]
pub reward_set: Option<RewardSet>,
}

#[derive(Deserialize, Serialize)]
pub struct RewardSet {
pub pox_ustx_threshold: String,
pub rewarded_addresses: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub signers: Option<Vec<RewardSetSigner>>,
}

#[derive(Deserialize, Serialize)]
pub struct RewardSetSigner {
pub signing_key: String,
pub weight: u32,
pub stacked_amt: String,
}

#[derive(Deserialize, Serialize, Default, Clone)]
Expand Down Expand Up @@ -461,6 +491,29 @@ pub fn standardize_stacks_block(
pox_cycle_length: pox_cycle_length.try_into().unwrap(),
confirm_microblock_identifier,
stacks_block_hash: block.block_hash.clone(),

block_time: block.block_time,
// TODO: decode `signer_bitvec` into an easy to use bit string representation (e.g. "01010101")
signer_bitvec: block.signer_bitvec.clone(),
signer_signature: block.signer_signature.clone(),

cycle_number: block.cycle_number,
reward_set: block.reward_set.as_ref().and_then(|r| {
Some(StacksBlockMetadataRewardSet {
pox_ustx_threshold: r.pox_ustx_threshold.clone(),
rewarded_addresses: r.rewarded_addresses.clone(),
signers: r.signers.as_ref().map(|signers| {
signers
.into_iter()
.map(|signer| StacksBlockMetadataRewardSetSigner {
signing_key: signer.signing_key.clone(),
weight: signer.weight,
stacked_amt: signer.stacked_amt.clone(),
})
.collect()
}),
})
}),
},
transactions,
};
Expand Down
Loading

0 comments on commit a47b3d2

Please sign in to comment.