Skip to content

Commit

Permalink
return opreturn in any situation (paritytech#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
atenjin authored and toxotguo committed May 20, 2019
1 parent 206af6c commit 1e20697
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
6 changes: 2 additions & 4 deletions rpc/src/chainx/impl_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,9 @@ where
}
if handicap.highest_bid > pair.fluctuation() {
info.minimum_offer = handicap.highest_bid - pair.fluctuation();
}else {
info.minimum_offer = 10_u64.pow(pair.tick_precision);//tick
} else {
info.minimum_offer = 10_u64.pow(pair.tick_precision); //tick
}

}

pairs.push(info);
Expand Down Expand Up @@ -650,7 +649,6 @@ where
highest_bid - pair.fluctuation()
} else {
10_u64.pow(pair.tick_precision)

};

for price in (lowest_offer..=maximum_bid).step_by(tick as usize) {
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion xrml/xbridge/bitcoin/src/assets_records.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ impl<T: Trait> Module<T> {
.layout()
.to_vec(),
),
ext,
ext: ext.unwrap_or_default(), // op return
height_or_time:
HeightOrTime::<T::BlockNumber, T::Moment>::Timestamp(
As::sa(timestamp as u64),
Expand Down
21 changes: 10 additions & 11 deletions xrml/xbridge/bitcoin/src/tx/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,22 @@ impl TxHandler {
})
.expect("must set input addr before; qed");

let (account_info, deposit_balance, original_opretion) =
let (account_info, deposit_balance, original_opreturn) =
parse_deposit_outputs::<T>(&self.tx_info.raw_tx)?;
let original_opreturn = original_opreturn.unwrap_or_default();

debug!(
"[deposit]|parse outputs|account_info:{:?}|balance:{:}|opreturn:{:}|",
account_info,
deposit_balance,
if original_opretion.len() > 2 {
if original_opreturn.len() > 2 {
format!(
"{:?}|{:}",
original_opretion[..2].to_vec(),
u8array_to_string(&original_opretion[2..])
original_opreturn[..2].to_vec(),
u8array_to_string(&original_opreturn[2..])
)
} else {
u8array_to_string(&original_opretion)
u8array_to_string(&original_opreturn)
}
);

Expand Down Expand Up @@ -216,7 +217,7 @@ impl TxHandler {
xassets::Chain::Bitcoin,
Module::<T>::TOKEN.to_vec(),
As::sa(deposit_balance),
original_opretion,
original_opreturn,
b58::to_base58(input_addr.layout().to_vec()),
self.tx_hash.as_bytes().to_vec(),
xrecords::TxState::Confirmed,
Expand All @@ -233,12 +234,12 @@ fn handle_opreturn<T: Trait>(script: &[u8], addr_type: u8) -> Option<(T::Account

pub fn parse_deposit_outputs<T: Trait>(
tx: &Transaction,
) -> result::Result<(Option<(T::AccountId, Option<Name>)>, u64, Vec<u8>), &'static str> {
) -> result::Result<(Option<(T::AccountId, Option<Name>)>, u64, Option<Vec<u8>>), &'static str> {
let trustee_address = get_hot_trustee_address::<T>()?;
let mut deposit_balance = 0;
let mut account_info = None;
let mut has_opreturn = false;
let mut original = Vec::new();
let mut original = None;
// parse
for output in tx.outputs.iter() {
// out script
Expand All @@ -251,9 +252,7 @@ pub fn parse_deposit_outputs<T: Trait>(
// OP_CODE PUSH ... (2 BYTES)
let addr_type = xsystem::Module::<T>::address_type();
account_info = handle_opreturn::<T>(&script[2..], addr_type);
if account_info.is_some() {
original.extend(script.to_vec());
}
original = Some(script.to_vec());
has_opreturn = true;
}
continue;
Expand Down

0 comments on commit 1e20697

Please sign in to comment.