From 1504d807791ae6a49420a382c01ceec18e03eb05 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 22:13:23 -0500 Subject: [PATCH 1/4] feat: add lockup events --- src/chainstate/stacks/db/mod.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index 207fa799201..7cf63f030ec 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -988,12 +988,26 @@ impl StacksChainState { .with_clarity_db(|db| { for (block_height, schedule) in lockups_per_block.into_iter() { let key = Value::UInt(block_height.into()); + let value = Value::list_from(schedule).unwrap(); db.insert_entry( &lockup_contract_id, "lockups", - key, - Value::list_from(schedule).unwrap(), + key.clone(), + value.clone(), )?; + + // Attach some events + let lookup_event = TupleData::from_data(vec![ + (ClarityName::try_from("block-height").unwrap(), key), + (ClarityName::try_from("due-schedules").unwrap(), value) + ]).unwrap(); + let lookup_event = StacksTransactionEvent::SmartContractEvent( + SmartContractEventData { + key: (boot_code_id("lockup"), "print".to_string()), + value: Value::Tuple(lookup_event) + } + ); + allocation_events.push(lookup_event); } Ok(()) }) From 34854e43dbc888f1ad85736ab5ea1ba21f4e39c1 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 22:24:45 -0500 Subject: [PATCH 2/4] feat: add lockup receipt --- src/chainstate/stacks/db/mod.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index 7cf63f030ec..027756309d3 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -957,6 +957,7 @@ impl StacksChainState { ); receipts.push(allocations_receipt); + let mut lockup_events: Vec = vec![]; if let Some(get_schedules) = boot_data.get_bulk_initial_lockups.take() { info!("Initializing chain with lockups"); let mut lockups_per_block: BTreeMap> = BTreeMap::new(); @@ -1007,13 +1008,31 @@ impl StacksChainState { value: Value::Tuple(lookup_event) } ); - allocation_events.push(lookup_event); + lockup_events.push(lookup_event); } Ok(()) }) .unwrap(); }); } + let lockup_tx = StacksTransaction::new( + tx_version.clone(), + boot_code_auth.clone(), + TransactionPayload::ContractCall(TransactionContractCall { + address: boot_code_address, + contract_name: ContractName::try_from("lockup").unwrap(), + function_name: ClarityName::try_from("genesis").unwrap(), + function_args: vec![], + } + ), + ); + let lockup_receipt = StacksTransactionReceipt::from_stx_transfer( + lockup_tx, + lockup_events, + Value::okay_true(), + ExecutionCost::zero(), + ); + receipts.push(lockup_receipt); if let Some(callback) = boot_data.post_flight_callback.take() { callback(&mut clarity_tx); From c54036807026da041f534147413d2a2df6715895 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 22:28:04 -0500 Subject: [PATCH 3/4] chore: cargo fmt --- src/chainstate/burn/operations/mod.rs | 10 ++++------ src/chainstate/stacks/db/mod.rs | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/chainstate/burn/operations/mod.rs b/src/chainstate/burn/operations/mod.rs index 8a16cd80fc5..10c343e2fe7 100644 --- a/src/chainstate/burn/operations/mod.rs +++ b/src/chainstate/burn/operations/mod.rs @@ -118,12 +118,10 @@ impl fmt::Display for Error { Error::BlockCommitBadModulus => { write!(f, "Block commit included a bad burn block height modulus") } - Error::MissedBlockCommit(_) => { - write!( - f, - "Block commit included in a burn block that was not intended" - ) - } + Error::MissedBlockCommit(_) => write!( + f, + "Block commit included in a burn block that was not intended" + ), Error::LeaderKeyAlreadyRegistered => { write!(f, "Leader key has already been registered") } diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index 027756309d3..58fc022dc92 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -1000,13 +1000,14 @@ impl StacksChainState { // Attach some events let lookup_event = TupleData::from_data(vec![ (ClarityName::try_from("block-height").unwrap(), key), - (ClarityName::try_from("due-schedules").unwrap(), value) - ]).unwrap(); + (ClarityName::try_from("due-schedules").unwrap(), value), + ]) + .unwrap(); let lookup_event = StacksTransactionEvent::SmartContractEvent( SmartContractEventData { key: (boot_code_id("lockup"), "print".to_string()), - value: Value::Tuple(lookup_event) - } + value: Value::Tuple(lookup_event), + }, ); lockup_events.push(lookup_event); } @@ -1019,12 +1020,11 @@ impl StacksChainState { tx_version.clone(), boot_code_auth.clone(), TransactionPayload::ContractCall(TransactionContractCall { - address: boot_code_address, - contract_name: ContractName::try_from("lockup").unwrap(), - function_name: ClarityName::try_from("genesis").unwrap(), - function_args: vec![], - } - ), + address: boot_code_address, + contract_name: ContractName::try_from("lockup").unwrap(), + function_name: ClarityName::try_from("genesis").unwrap(), + function_args: vec![], + }), ); let lockup_receipt = StacksTransactionReceipt::from_stx_transfer( lockup_tx, From 62d90f0da36f79ec84d5a46143174637b44b962c Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 30 Dec 2020 12:03:53 -0500 Subject: [PATCH 4/4] chore: cargo fmt --- src/chainstate/stacks/db/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index b0bce868e53..6448d71564f 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -1207,7 +1207,6 @@ impl StacksChainState { ); receipts.push(allocations_receipt); - let lockup_tx = StacksTransaction::new( tx_version.clone(), boot_code_auth.clone(),