Skip to content

Commit

Permalink
chore: upgrade contracts to use the new spv proof
Browse files Browse the repository at this point in the history
  • Loading branch information
sander2 committed Jul 24, 2023
1 parent 7d32ca6 commit 01c6c60
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 232 deletions.
19 changes: 4 additions & 15 deletions contracts/btc_swap/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std, no_main)]

use bitcoin::types::{MerkleProof, Transaction};
use bitcoin::types::{FullTransactionProof, MerkleProof, Transaction};
use ink::{env::Environment, prelude::vec::Vec};

#[derive(Debug, Clone, PartialEq, Eq)]
Expand All @@ -26,12 +26,7 @@ pub trait DoSomethingInRuntime {
/// Note: this gives the operation a corresponding `func_id` (1101 in this case),
/// and the chain-side chain extension will get the `func_id` to do further operations.
#[ink(extension = 1101)]
fn get_and_verify_bitcoin_payment(
merkle_proof: MerkleProof,
transaction: Transaction,
length_bound: u32,
address: Vec<u8>,
) -> Option<u64>;
fn get_and_verify_bitcoin_payment(full_proof: FullTransactionProof, address: Vec<u8>) -> Option<u64>;
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
Expand Down Expand Up @@ -118,20 +113,14 @@ mod btc_swap {
}

#[ink(message)]
pub fn execute_trade(
&mut self,
counterparty: AccountId,
merkle_proof: MerkleProof,
transaction: Transaction,
length_bound: u32,
) {
pub fn execute_trade(&mut self, counterparty: AccountId, full_proof: FullTransactionProof) {
let caller = self.env().caller();
let order = self.orders.get(&counterparty).unwrap();

let transferred_sats = self
.env()
.extension()
.get_and_verify_bitcoin_payment(merkle_proof, transaction, length_bound)
.get_and_verify_bitcoin_payment(full_proof, order.btc_address)
.unwrap()
.unwrap_or(0);

Expand Down
Loading

0 comments on commit 01c6c60

Please sign in to comment.