From fa57474232103f1437bf03a597ddc587c8d759d5 Mon Sep 17 00:00:00 2001 From: jolestar Date: Sat, 14 Sep 2024 10:21:32 +0800 Subject: [PATCH] [framework] Binding bitcoin address when transfer (#2628) --- frameworks/rooch-framework/sources/address_mapping.move | 1 + frameworks/rooch-framework/sources/tests/transfer_test.move | 5 +++++ frameworks/rooch-framework/sources/transfer.move | 2 ++ 3 files changed, 8 insertions(+) diff --git a/frameworks/rooch-framework/sources/address_mapping.move b/frameworks/rooch-framework/sources/address_mapping.move index 7c47be75d2..e7e6bbdef0 100644 --- a/frameworks/rooch-framework/sources/address_mapping.move +++ b/frameworks/rooch-framework/sources/address_mapping.move @@ -12,6 +12,7 @@ module rooch_framework::address_mapping{ friend rooch_framework::genesis; friend rooch_framework::bitcoin_validator; friend rooch_framework::transaction_validator; + friend rooch_framework::transfer; const ErrorMultiChainAddressInvalid: u64 = 1; const ErrorUnsupportedAddress: u64 = 2; diff --git a/frameworks/rooch-framework/sources/tests/transfer_test.move b/frameworks/rooch-framework/sources/tests/transfer_test.move index 799a4a2af9..7162394f5e 100644 --- a/frameworks/rooch-framework/sources/tests/transfer_test.move +++ b/frameworks/rooch-framework/sources/tests/transfer_test.move @@ -81,6 +81,11 @@ module rooch_framework::transfer_test{ transfer::transfer_coin_to_bitcoin_address(&from_signer, bitcoin_address_str, 11u256); assert!(gas_coin::balance(from) == original_balance - 11u256, 1002); assert!(gas_coin::balance(to_rooch_address) == 11u256, 1003); + + let opt_addr = address_mapping::resolve_bitcoin(to_rooch_address); + assert!(option::is_some(&opt_addr), 1004); + let addr = option::destroy_some(opt_addr); + assert!(addr == btc_address, 1005); } #[test_only] diff --git a/frameworks/rooch-framework/sources/transfer.move b/frameworks/rooch-framework/sources/transfer.move index 34047c3ce1..deb0f0e78e 100644 --- a/frameworks/rooch-framework/sources/transfer.move +++ b/frameworks/rooch-framework/sources/transfer.move @@ -32,6 +32,7 @@ module rooch_framework::transfer { ) { let btc_address = bitcoin_address::from_string(&to); let rooch_address = bitcoin_address::to_rooch_address(&btc_address); + address_mapping::bind_bitcoin_address(rooch_address, btc_address); account_coin_store::transfer(from, rooch_address, amount) } @@ -62,6 +63,7 @@ module rooch_framework::transfer { obj: Object) { let btc_address = bitcoin_address::from_string(&to); let rooch_address = bitcoin_address::to_rooch_address(&btc_address); + address_mapping::bind_bitcoin_address(rooch_address, btc_address); object::transfer(obj, rooch_address); } }