@@ -751,6 +751,51 @@ impl Streamer for MicroblockStreamData {
751
751
}
752
752
}
753
753
754
+ enum Token {
755
+ Nft { id : u128 } ,
756
+ Ft { amount : u128 } ,
757
+ }
758
+
759
+ fn make_withdrawal_event (
760
+ subnet_contract_id : QualifiedContractIdentifier ,
761
+ sender : PrincipalData ,
762
+ token : Token ,
763
+ mainnet : bool ,
764
+ ) -> StacksTransactionEvent {
765
+ let ( withdrawal_type, mut values) = match token {
766
+ Token :: Nft { id } => ( "nft" , vec ! [ ( "id" . into( ) , Value :: UInt ( id) ) ] ) ,
767
+ Token :: Ft { amount } => ( "ft" , vec ! [ ( "amount" . into( ) , Value :: UInt ( amount) ) ] ) ,
768
+ } ;
769
+
770
+ values. extend (
771
+ vec ! [
772
+ (
773
+ "event" . into( ) ,
774
+ Value :: string_ascii_from_bytes( "withdraw" . into( ) )
775
+ . expect( "Supplied string was not ASCII" ) ,
776
+ ) ,
777
+ (
778
+ "type" . into( ) ,
779
+ Value :: string_ascii_from_bytes( withdrawal_type. into( ) )
780
+ . expect( "Supplied string was not ASCII" ) ,
781
+ ) ,
782
+ ( "sender" . into( ) , Value :: Principal ( sender) ) ,
783
+ (
784
+ "asset-contract" . into( ) ,
785
+ Value :: Principal ( PrincipalData :: Contract ( subnet_contract_id) ) ,
786
+ ) ,
787
+ ]
788
+ . into_iter ( ) ,
789
+ ) ;
790
+
791
+ StacksTransactionEvent :: SmartContractEvent ( SmartContractEventData {
792
+ key : ( boot_code_id ( "subnet" , mainnet) , "print" . into ( ) ) ,
793
+ value : TupleData :: from_data ( values)
794
+ . expect ( "Failed to create tuple data." )
795
+ . into ( ) ,
796
+ } )
797
+ }
798
+
754
799
impl StacksChainState {
755
800
fn get_index_block_pathbuf ( blocks_dir : & str , index_block_hash : & StacksBlockId ) -> PathBuf {
756
801
let block_hash_bytes = index_block_hash. as_bytes ( ) ;
@@ -4710,45 +4755,13 @@ impl StacksChainState {
4710
4755
. collect ( )
4711
4756
}
4712
4757
4713
- fn make_nft_withdrawal_event (
4714
- subnet_contract_id : QualifiedContractIdentifier ,
4715
- sender : PrincipalData ,
4716
- id : u128 ,
4717
- mainnet : bool ,
4718
- ) -> StacksTransactionEvent {
4719
- StacksTransactionEvent :: SmartContractEvent ( SmartContractEventData {
4720
- key : ( boot_code_id ( "subnet" , mainnet) , "print" . into ( ) ) ,
4721
- value : TupleData :: from_data ( vec ! [
4722
- (
4723
- "event" . into( ) ,
4724
- Value :: string_ascii_from_bytes( "withdraw" . into( ) )
4725
- . expect( "Supplied string was not ASCII" ) ,
4726
- ) ,
4727
- (
4728
- "type" . into( ) ,
4729
- Value :: string_ascii_from_bytes( "nft" . into( ) )
4730
- . expect( "Supplied string was not ASCII" ) ,
4731
- ) ,
4732
- ( "sender" . into( ) , Value :: Principal ( sender) ) ,
4733
- ( "id" . into( ) , Value :: UInt ( id) ) ,
4734
- (
4735
- "asset-contract" . into( ) ,
4736
- Value :: Principal ( PrincipalData :: Contract ( subnet_contract_id) ) ,
4737
- ) ,
4738
- ] )
4739
- . expect ( "Failed to create tuple data." )
4740
- . into ( ) ,
4741
- } )
4742
- }
4743
-
4744
4758
/// Process any deposit NFT operations that haven't been processed in this
4745
4759
/// subnet fork yet.
4746
4760
pub fn process_deposit_nft_ops (
4747
4761
clarity_tx : & mut ClarityTx ,
4748
4762
operations : Vec < DepositNftOp > ,
4749
4763
) -> Vec < StacksTransactionReceipt > {
4750
4764
let mainnet = clarity_tx. config . mainnet ;
4751
- let boot_addr = PrincipalData :: from ( boot_code_addr ( mainnet) ) ;
4752
4765
let cost_so_far = clarity_tx. cost_so_far ( ) ;
4753
4766
// return valid receipts
4754
4767
operations
@@ -4764,7 +4777,7 @@ impl StacksChainState {
4764
4777
} = deposit_nft_op. clone ( ) ;
4765
4778
let result = clarity_tx. connection ( ) . as_transaction ( |tx| {
4766
4779
tx. run_contract_call (
4767
- & boot_addr ,
4780
+ & boot_code_addr ( mainnet ) . into ( ) ,
4768
4781
None ,
4769
4782
& subnet_contract_id,
4770
4783
DEPOSIT_FUNCTION_NAME ,
@@ -4792,10 +4805,10 @@ impl StacksChainState {
4792
4805
// If deposit fails, create a withdrawal event to send NFT back to user
4793
4806
if deposit_op_failed {
4794
4807
info ! ( "DepositNft op failed. Issue withdrawal tx" ) ;
4795
- events. push ( Self :: make_nft_withdrawal_event (
4808
+ events. push ( make_withdrawal_event (
4796
4809
subnet_contract_id,
4797
4810
sender,
4798
- id ,
4811
+ Token :: Nft { id } ,
4799
4812
mainnet,
4800
4813
) ) ;
4801
4814
} ;
0 commit comments