mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-13 16:19:01 +08:00
feat: add support for bitcoin op DelegatedStacking
This commit is contained in:
@@ -2,13 +2,14 @@ mod blocks_pool;
|
||||
|
||||
pub use blocks_pool::StacksBlockPool;
|
||||
|
||||
use crate::chainhooks::stacks::try_decode_clarity_value;
|
||||
use crate::indexer::AssetClassCache;
|
||||
use crate::indexer::{IndexerConfig, StacksChainContext};
|
||||
use crate::utils::Context;
|
||||
use chainhook_types::*;
|
||||
use clarity_repl::clarity::codec::StacksMessageCodec;
|
||||
use clarity_repl::clarity::util::hash::hex_bytes;
|
||||
use clarity_repl::clarity::vm::types::Value as ClarityValue;
|
||||
use clarity_repl::clarity::vm::types::{SequenceData, Value as ClarityValue};
|
||||
use clarity_repl::codec::{StacksTransaction, TransactionAuth, TransactionPayload};
|
||||
use hiro_system_kit::slog;
|
||||
use rocket::serde::json::Value as JsonValue;
|
||||
@@ -539,8 +540,108 @@ pub fn get_tx_description(
|
||||
"stacked: {} µSTX by {} through Bitcoin transaction",
|
||||
data.locked_amount, data.locked_address,
|
||||
);
|
||||
let tx_type = StacksTransactionKind::Other;
|
||||
let tx_type =
|
||||
StacksTransactionKind::BitcoinOp(BitcoinOpData::StackSTX(StackSTXData {
|
||||
locked_amount: data.locked_amount,
|
||||
unlock_height: data.unlock_height,
|
||||
stacking_address: data.locked_address.clone(),
|
||||
}));
|
||||
return Ok((description, tx_type, 0, 0, data.locked_address, None));
|
||||
} else if let Some(ref event_data) = event.contract_event {
|
||||
let data: SmartContractEventData = serde_json::from_value(event_data.clone())
|
||||
.map_err(|e| format!("unable to decode event_data {}", e.to_string()))?;
|
||||
if let Some(ClarityValue::Response(data)) =
|
||||
try_decode_clarity_value(&data.hex_value)
|
||||
{
|
||||
if data.committed {
|
||||
if let ClarityValue::Tuple(outter) = *data.data {
|
||||
if let Some(ClarityValue::Tuple(inner)) = outter.data_map.get("data") {
|
||||
match (
|
||||
&outter.data_map.get("stacker"),
|
||||
&inner.data_map.get("amount-ustx"),
|
||||
&inner.data_map.get("delegate-to"),
|
||||
&inner.data_map.get("pox-addr"),
|
||||
&inner.data_map.get("unlock-burn-height"),
|
||||
) {
|
||||
(
|
||||
Some(ClarityValue::Principal(stacking_address)),
|
||||
Some(ClarityValue::UInt(amount_ustx)),
|
||||
Some(ClarityValue::Principal(delegate)),
|
||||
Some(ClarityValue::Optional(pox_addr)),
|
||||
Some(ClarityValue::Optional(unlock_burn_height)),
|
||||
) => {
|
||||
let description = format!(
|
||||
"stacked: {} µSTX delegated to {} through Bitcoin transaction",
|
||||
amount_ustx, delegate.to_string(),
|
||||
);
|
||||
let tx_type = StacksTransactionKind::BitcoinOp(
|
||||
BitcoinOpData::DelegateStackSTX(DelegateStackSTXData {
|
||||
stacking_address: stacking_address.to_string(),
|
||||
amount: amount_ustx.to_string(),
|
||||
delegate: delegate.to_string(),
|
||||
pox_address: match &pox_addr.data {
|
||||
Some(value) => match &**value {
|
||||
ClarityValue::Tuple(address_comps) => {
|
||||
match (
|
||||
&address_comps
|
||||
.data_map
|
||||
.get("version"),
|
||||
&address_comps
|
||||
.data_map
|
||||
.get("hashbytes"),
|
||||
) {
|
||||
(
|
||||
Some(ClarityValue::UInt(
|
||||
_version,
|
||||
)),
|
||||
Some(ClarityValue::Sequence(
|
||||
SequenceData::Buffer(
|
||||
_hashbytes,
|
||||
),
|
||||
)),
|
||||
) => None,
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
unlock_height: match &*(&unlock_burn_height.data) {
|
||||
Some(value) => match &**value {
|
||||
ClarityValue::UInt(value) => {
|
||||
Some(value.to_string())
|
||||
}
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
}),
|
||||
);
|
||||
return Ok((
|
||||
description,
|
||||
tx_type,
|
||||
0,
|
||||
0,
|
||||
"".to_string(),
|
||||
None,
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Ok((
|
||||
"unsupported transaction".into(),
|
||||
StacksTransactionKind::Unsupported,
|
||||
0,
|
||||
0,
|
||||
"".to_string(),
|
||||
None,
|
||||
));
|
||||
}
|
||||
}
|
||||
return Err(format!(
|
||||
@@ -627,7 +728,7 @@ pub fn get_tx_description(
|
||||
TransactionPayload::Coinbase(_, _) => {
|
||||
(format!("coinbase"), StacksTransactionKind::Coinbase)
|
||||
}
|
||||
_ => (format!("other"), StacksTransactionKind::Other),
|
||||
_ => (format!("other"), StacksTransactionKind::Unsupported),
|
||||
};
|
||||
Ok((description, tx_type, fee, nonce, sender, sponsor))
|
||||
}
|
||||
|
||||
@@ -149,7 +149,31 @@ pub enum StacksTransactionKind {
|
||||
ContractDeployment(StacksContractDeploymentData),
|
||||
NativeTokenTransfer,
|
||||
Coinbase,
|
||||
Other,
|
||||
BitcoinOp(BitcoinOpData),
|
||||
Unsupported,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(tag = "type", content = "data")]
|
||||
pub enum BitcoinOpData {
|
||||
StackSTX(StackSTXData),
|
||||
DelegateStackSTX(DelegateStackSTXData),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct StackSTXData {
|
||||
pub locked_amount: String,
|
||||
pub unlock_height: String,
|
||||
pub stacking_address: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
pub struct DelegateStackSTXData {
|
||||
pub stacking_address: String,
|
||||
pub amount: String,
|
||||
pub delegate: String,
|
||||
pub pox_address: Option<String>,
|
||||
pub unlock_height: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user