Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[framework] Binding bitcoin address when transfer #2628

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frameworks/rooch-framework/sources/address_mapping.move
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions frameworks/rooch-framework/sources/tests/transfer_test.move
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ module rooch_framework::transfer_test{
transfer::transfer_coin_to_bitcoin_address<RGas>(&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]
Expand Down
2 changes: 2 additions & 0 deletions frameworks/rooch-framework/sources/transfer.move
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoinType>(from, rooch_address, amount)
}

Expand Down Expand Up @@ -62,6 +63,7 @@ module rooch_framework::transfer {
obj: Object<T>) {
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);
}
}
Loading