Skip to content

Commit

Permalink
Stage/bridge btc (#93)
Browse files Browse the repository at this point in the history
* Fix test build

* Fix op_return account id parse

* Fix merge error

* update genesis_config

* Update genesis_config

* x-btc

* Update latest bitcoin-rust dependeces

* Fix insert registration information failure (paritytech#91)

* Change receive_address type
  • Loading branch information
eee-byte authored and gguoss committed Nov 16, 2018
1 parent 2dda47c commit d559a5a
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 135 deletions.
52 changes: 35 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ log = "0.3"
# bitcoin-rust
primitives = { git = "https://github.com/chainx-org/bitcoin-rust" }
chain = { git = "https://github.com/chainx-org/bitcoin-rust" }
keys = { git = "https://github.com/chainx-org/bitcoin-rust" }

[workspace]
members = [
Expand Down
20 changes: 2 additions & 18 deletions cxrml/bridge/btc/src/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,34 +165,18 @@ impl<T: Trait> Chain<T> {
best_number + 1
},
};
if let Some(vec) = <DepositCache<T>>::take() {
let mut uncomplete_cache: Vec<(T::AccountId, u64, H256)> = Vec::new();
for (account_id, amount, block_hash) in vec {
let symbol: Symbol = b"x-btc".to_vec();
let irr_block = <IrrBlock<T>>::get();
match <NumberForHash<T>>::get(block_hash.clone()) {
Some(height) => {
if new_best_header.number > height + irr_block {
<finacial_recordes::Module<T>>::deposit(&account_id, &symbol, As::sa(amount));
} else {
uncomplete_cache.push((account_id, amount, block_hash));
}
},
None => { uncomplete_cache.push((account_id, amount, block_hash)); }, // Optmise
}
}
<DepositCache<T>>::put(uncomplete_cache);
}

let symbol: Symbol = b"x-btc".to_vec();
let irr_block = <IrrBlock<T>>::get();
// Deposit
if let Some(vec) = <DepositCache<T>>::take() {
runtime_io::print("------DepositCache take");
let mut uncomplete_cache: Vec<(T::AccountId, u64, H256)> = Vec::new();
for (account_id, amount, block_hash) in vec {
match <NumberForHash<T>>::get(block_hash.clone()) {
Some(height) => {
if new_best_header.number > height + irr_block {
runtime_io::print("------finacial_recordes deposit");
<finacial_recordes::Module<T>>::deposit(
&account_id,
&symbol,
Expand Down
9 changes: 3 additions & 6 deletions cxrml/bridge/btc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ decl_storage! {

// =====
// tx
pub ReceiveAddress get(receive_address) config(): Option<Vec<u8>>;
pub ReceiveAddress get(receive_address) config(): Option<keys::Address>;
pub RedeemScript get(redeem_script) config(): Option<Vec<u8>>;

pub UTXOSet get(utxo_set): map u64 => UTXO;
Expand All @@ -216,7 +216,7 @@ decl_storage! {
pub DepositCache get(deposit_cache): Option<Vec<(T::AccountId, u64, H256)>>; // account_id, amount, H256

pub AccountsMaxIndex get(accounts_max_index) config(): u64;
pub AccountsSet get(accounts_set): map u64 => Option<(H256, keys::Address, T::AccountId, u32, TxType)>;
pub AccountsSet get(accounts_set): map u64 => Option<(H256, keys::Address, T::AccountId, T::BlockNumber, TxType)>;

// =====
// others
Expand Down Expand Up @@ -326,15 +326,12 @@ impl<T: Trait> Module<T> {
}

pub fn process_tx(tx: RelayTx, who: &T::AccountId) -> Result {
let receive_address: Vec<u8> = if let Some(h) = <ReceiveAddress<T>>::get() {
let receive_address: keys::Address = if let Some(h) = <ReceiveAddress<T>>::get() {
h
} else {
return Err("should set RECEIVE_address first");
};

runtime_io::print("-------receive address:");
runtime_io::print(receive_address.as_slice());

let tx_type = validate_transaction::<T>(&tx, &receive_address).unwrap();
match tx_type {
TxType::Withdraw => {
Expand Down
5 changes: 5 additions & 0 deletions cxrml/bridge/btc/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn new_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
network_id: 1,
utxo_max_index: 0,
irr_block: 6,
btc_fee: 10,
accounts_max_index: 0,
receive_address: "mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b".from_base58().unwrap(),
redeem_script: b"52210257aff1270e3163aaae9d972b3d09a2385e0d4877501dbeca3ee045f8de00d21c2103fd58c689594b87bbe20a9a00091d074dc0d9f49a988a7ad4c2575adeda1b507c2102bb2a5aa53ba7c0d77bdd86bb9553f77dd0971d3a6bb6ad609787aa76eb17b6b653ae".to_vec(),
Expand Down Expand Up @@ -149,6 +150,7 @@ pub fn new_test_ext_err_genesisblock() -> runtime_io::TestExternalities<Blake2Ha
network_id: 0,
utxo_max_index: 0,
irr_block: 6,
btc_fee: 10,
accounts_max_index: 0,
receive_address: "mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b".from_base58().unwrap(),
redeem_script: b"52210257aff1270e3163aaae9d972b3d09a2385e0d4877501dbeca3ee045f8de00d21c2103fd58c689594b87bbe20a9a00091d074dc0d9f49a988a7ad4c2575adeda1b507c2102bb2a5aa53ba7c0d77bdd86bb9553f77dd0971d3a6bb6ad609787aa76eb17b6b653ae".to_vec(),
Expand Down Expand Up @@ -265,6 +267,7 @@ pub fn new_test_mock_ext() -> runtime_io::TestExternalities<Blake2Hasher> {
network_id: 1,
utxo_max_index: 0,
irr_block: 6,
btc_fee: 10,
accounts_max_index: 0,
receive_address: "mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b".from_base58().unwrap(),
redeem_script: b"52210257aff1270e3163aaae9d972b3d09a2385e0d4877501dbeca3ee045f8de00d21c2103fd58c689594b87bbe20a9a00091d074dc0d9f49a988a7ad4c2575adeda1b507c2102bb2a5aa53ba7c0d77bdd86bb9553f77dd0971d3a6bb6ad609787aa76eb17b6b653ae".to_vec(),
Expand Down Expand Up @@ -644,6 +647,7 @@ pub fn new_test_ext2() -> runtime_io::TestExternalities<Blake2Hasher> {
network_id: 1,
utxo_max_index: 0,
irr_block: 6,
btc_fee: 10,
accounts_max_index: 0,
receive_address: "mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b".from_base58().unwrap(),
redeem_script: b"52210257aff1270e3163aaae9d972b3d09a2385e0d4877501dbeca3ee045f8de00d21c2103fd58c689594b87bbe20a9a00091d074dc0d9f49a988a7ad4c2575adeda1b507c2102bb2a5aa53ba7c0d77bdd86bb9553f77dd0971d3a6bb6ad609787aa76eb17b6b653ae".to_vec(),
Expand Down Expand Up @@ -716,6 +720,7 @@ pub fn new_test_ext3() -> runtime_io::TestExternalities<Blake2Hasher> {
network_id: 1,
utxo_max_index: 0,
irr_block: 6,
btc_fee: 10,
accounts_max_index: 0,
receive_address: "mjKE11gjVN4JaC9U8qL6ZB5vuEBgmwik7b".from_base58().unwrap(),
redeem_script: b"52210257aff1270e3163aaae9d972b3d09a2385e0d4877501dbeca3ee045f8de00d21c2103fd58c689594b87bbe20a9a00091d074dc0d9f49a988a7ad4c2575adeda1b507c2102bb2a5aa53ba7c0d77bdd86bb9553f77dd0971d3a6bb6ad609787aa76eb17b6b653ae".to_vec(),
Expand Down
Loading

0 comments on commit d559a5a

Please sign in to comment.