diff --git a/Cargo.lock b/Cargo.lock index 764fe81b8..6dc58a461 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -489,6 +489,7 @@ dependencies = [ name = "chainhook-types" version = "1.0.12" dependencies = [ + "clarity-vm", "hex", "schemars 0.8.12", "serde", diff --git a/components/chainhook-sdk/src/chainhooks/tests/fixtures/stacks/testnet/base/transaction_contract_deploy.json b/components/chainhook-sdk/src/chainhooks/tests/fixtures/stacks/testnet/base/transaction_contract_deploy.json index f6693dedc..6502f6428 100644 --- a/components/chainhook-sdk/src/chainhooks/tests/fixtures/stacks/testnet/base/transaction_contract_deploy.json +++ b/components/chainhook-sdk/src/chainhooks/tests/fixtures/stacks/testnet/base/transaction_contract_deploy.json @@ -20,7 +20,45 @@ "position": { "index": 1 }, - "contract_abi": "some abi data", + "contract_abi": { + "clarity_version": "Clarity2", + "epoch": "Epoch24", + "functions": [ + { + "access": "private", + "args": [{ "name": "tid", "type": "uint128" }], + "name": "airdrop", + "outputs": { "type": "bool" } + } + ], + "fungible_tokens": [{ "name": "MEME" }], + "maps": [ + { + "key": { + "tuple": [ + { + "name": "name", + "type": { "buffer": { "length": 48 } } + }, + { + "name": "namespace", + "type": { "buffer": { "length": 20 } } + } + ] + }, + "name": "map_claimed_bns_note", + "value": "bool" + } + ], + "non_fungible_tokens": [], + "variables": [ + { + "access": "constant", + "name": "AIRDROP_COUNT_PER_MEMBER", + "type": "uint128" + } + ] + }, "proof": null, "raw_tx": "0x808000000004003e44ad50f99edc5e6cc5543b636284186894a008000000000000002100000000000b71b00000a84691e27fd2d46475230707a657ef7ddf6de7a4b06a1ac2049384c6474e73f85ee4ce205e0904160adaa160498df02db1782f898b5905db4d249b7025f6604c030100000000060218666169722d616d6172616e74682d7268696e6f6365726f73000005103b3b2068656c6c6f2d776f726c6420636f6e74726163740a0a28646566696e652d636f6e7374616e742073656e6465722027535a324a365a593438475631455a35563256355242394d5036365357383650594b4b51394836445052290a28646566696e652d636f6e7374616e7420726563697069656e742027534d324a365a593438475631455a35563256355242394d5036365357383650594b4b51565838583047290a0a28646566696e652d66756e6769626c652d746f6b656e206e6f76656c2d746f6b656e2d3139290a28626567696e202866742d6d696e743f206e6f76656c2d746f6b656e2d3139207531322073656e64657229290a28626567696e202866742d7472616e736665723f206e6f76656c2d746f6b656e2d31392075322073656e64657220726563697069656e7429290a0a28646566696e652d6e6f6e2d66756e6769626c652d746f6b656e2068656c6c6f2d6e66742075696e74290a28626567696e20286e66742d6d696e743f2068656c6c6f2d6e66742075312073656e64657229290a28626567696e20286e66742d6d696e743f2068656c6c6f2d6e66742075322073656e64657229290a28626567696e20286e66742d7472616e736665723f2068656c6c6f2d6e66742075312073656e64657220726563697069656e7429290a0a28646566696e652d7075626c69632028746573742d656d69742d6576656e74290a2020202028626567696e0a2020202020202020287072696e7420224576656e74212048656c6c6f20776f726c6422290a2020202020202020286f6b2075312929290a28626567696e2028746573742d656d69742d6576656e7429290a0a28646566696e652d7075626c69632028746573742d6576656e742d7479706573290a2020202028626567696e0a202020202020202028756e777261702d70616e6963202866742d6d696e743f206e6f76656c2d746f6b656e2d313920753320726563697069656e7429290a202020202020202028756e777261702d70616e696320286e66742d6d696e743f2068656c6c6f2d6e667420753220726563697069656e7429290a202020202020202028756e777261702d70616e696320287374782d7472616e736665723f207536302074782d73656e6465722027535a324a365a593438475631455a35563256355242394d5036365357383650594b4b5139483644505229290a202020202020202028756e777261702d70616e696320287374782d6275726e3f207532302074782d73656e64657229290a2020202020202020286f6b2075312929290a0a28646566696e652d6d61702073746f7265207b6b65793a202862756666203332297d207b76616c75653a202862756666203332297d290a28646566696e652d7075626c696320286765742d76616c756520286b65792028627566662033322929290a2020202028626567696e0a2020202020202020286d6174636820286d61702d6765743f2073746f7265207b6b65793a206b65797d290a202020202020202020202020656e74727920286f6b20286765742076616c756520656e74727929290a202020202020202020202020286572722030292929290a28646566696e652d7075626c696320287365742d76616c756520286b65792028627566662033322929202876616c75652028627566662033322929290a2020202028626567696e0a2020202020202020286d61702d7365742073746f7265207b6b65793a206b65797d207b76616c75653a2076616c75657d290a2020202020202020286f6b207531292929", "receipt": { diff --git a/components/chainhook-sdk/src/indexer/stacks/mod.rs b/components/chainhook-sdk/src/indexer/stacks/mod.rs index 5763bc450..203edd7b1 100644 --- a/components/chainhook-sdk/src/indexer/stacks/mod.rs +++ b/components/chainhook-sdk/src/indexer/stacks/mod.rs @@ -1,6 +1,7 @@ mod blocks_pool; pub use blocks_pool::StacksBlockPool; +use stacks_rpc_client::clarity::vm::analysis::contract_interface_builder::ContractInterface; use crate::chainhooks::stacks::try_decode_clarity_value; use crate::indexer::AssetClassCache; @@ -76,7 +77,7 @@ pub struct NewTransaction { pub raw_result: String, pub raw_tx: String, pub execution_cost: Option, - pub contract_abi: Option, + pub contract_abi: Option, } #[derive(Deserialize, Debug)] @@ -90,7 +91,7 @@ pub struct NewMicroblockTransaction { pub microblock_sequence: usize, pub microblock_hash: String, pub microblock_parent_hash: String, - pub contract_abi: Option, + pub contract_abi: Option, } #[derive(Debug, Deserialize)] diff --git a/components/chainhook-types-rs/Cargo.toml b/components/chainhook-types-rs/Cargo.toml index de2f3263f..0f26e90b0 100644 --- a/components/chainhook-types-rs/Cargo.toml +++ b/components/chainhook-types-rs/Cargo.toml @@ -14,3 +14,4 @@ serde_derive = "1" strum = { version = "0.23.0", features = ["derive"] } schemars = { version = "0.8.10", git = "https://github.com/hirosystems/schemars.git", branch = "feat-chainhook-fixes" } hex = "0.4.3" +clarity-vm = "2.1.1" diff --git a/components/chainhook-types-rs/src/rosetta.rs b/components/chainhook-types-rs/src/rosetta.rs index 479d2279a..605c5bc1d 100644 --- a/components/chainhook-types-rs/src/rosetta.rs +++ b/components/chainhook-types-rs/src/rosetta.rs @@ -1,7 +1,7 @@ use super::bitcoin::{TxIn, TxOut}; use crate::events::*; +use clarity::vm::analysis::contract_interface_builder::ContractInterface; use schemars::JsonSchema; -use serde_json::Value; use std::cmp::Ordering; use std::collections::HashSet; use std::fmt::Display; @@ -221,7 +221,7 @@ pub struct StacksTransactionMetadata { pub position: StacksTransactionPosition, pub proof: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub contract_abi: Option, + pub contract_abi: Option, } /// TODO