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

Bitcoin Connector: Proof of Concept Implementation #1

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
aea8074
init project
olga24912 Oct 23, 2024
be243d1
add types project
olga24912 Oct 23, 2024
bdeb69f
transaction type
olga24912 Oct 23, 2024
e138594
decode tx
olga24912 Oct 23, 2024
f40da2d
add omniBTC
olga24912 Oct 25, 2024
dc3b39e
parse tx
olga24912 Oct 25, 2024
e377362
parse script
olga24912 Oct 25, 2024
a92d567
save pk
olga24912 Oct 25, 2024
bbdaa32
check transfered value
olga24912 Oct 25, 2024
ebf69a1
save omni_bitcoin account
olga24912 Oct 25, 2024
e13d511
add near plugins to omni btc
olga24912 Oct 25, 2024
983d802
transfer OmniBTC
olga24912 Oct 26, 2024
cf050d2
calculate tx hash
olga24912 Oct 28, 2024
a09aa2c
add storage for finalized txs
olga24912 Oct 28, 2024
c6a055e
deploy test contracts
olga24912 Oct 28, 2024
1564171
deploy contracts
olga24912 Oct 28, 2024
1de3bf8
add merkle proof args
olga24912 Oct 29, 2024
a327500
save svg
olga24912 Oct 29, 2024
fdc532c
check tx
olga24912 Oct 29, 2024
ca82e43
save utxos
olga24912 Oct 29, 2024
466168d
add ft_on_transfer
olga24912 Oct 29, 2024
0ef20b0
safe new_transfers
olga24912 Oct 29, 2024
29ae3b6
burn in omniBTC
olga24912 Oct 29, 2024
216fb44
log init transfer event
olga24912 Oct 29, 2024
87b90c1
simple get_unsigned_tx
olga24912 Oct 29, 2024
ce2ba18
get sign msg
olga24912 Oct 30, 2024
f80755b
mpc sign transaction
olga24912 Oct 30, 2024
39b340b
add sign_callback
olga24912 Oct 30, 2024
e6be478
save signed ransfer
olga24912 Oct 30, 2024
b359170
remove custom tx
olga24912 Oct 30, 2024
c360d20
save publick key
olga24912 Oct 30, 2024
efa30ad
fmt
olga24912 Oct 30, 2024
3377cc1
only one utxo
olga24912 Oct 30, 2024
860c1e1
return max UTXO
olga24912 Oct 30, 2024
dcfc7b1
change output
olga24912 Oct 30, 2024
f7389a4
get fee
olga24912 Oct 30, 2024
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
Prev Previous commit
Next Next commit
simple get_unsigned_tx
olga24912 committed Oct 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 87b90c16778fa4ad21a83079c7bc1b9a5a726f26
52 changes: 47 additions & 5 deletions near/connector/src/lib.rs
Original file line number Diff line number Diff line change
@@ -3,12 +3,12 @@ use bitcoin_types::connector_args::FinTransferArgs;
use near_plugins::{access_control, pause, AccessControlRole, AccessControllable, Pausable, Upgradable};
use near_sdk::borsh::{BorshSerialize, BorshDeserialize};
use near_sdk::{AccountId, Gas, near, Promise, require, BorshStorageKey, env, PromiseError, PromiseOrValue};
use near_sdk::collections::{LookupMap, LookupSet};
use near_sdk::collections::{LookupMap, LookupSet, Vector};
use near_sdk::json_types::U128;
use near_sdk::serde::{Deserialize, Serialize};
use near_sdk::PanicOnDefault;
use near_sdk::ext_contract;
use bitcoin_types::transaction::{ConsensusDecoder, NewTransferToBitcoin, Script, Transaction, UTXO};
use bitcoin_types::transaction::{ConsensusDecoder, NewTransferToBitcoin, OutPoint, Script, Transaction, TxIn, TxOut, UTXO};
use btc_types::hash::H256;
use near_contract_standards::fungible_token::receiver::FungibleTokenReceiver;
use bitcoin_types::bitcoin_connector_events::BitcoinConnectorEvent;
@@ -55,7 +55,7 @@ pub struct BitcoinConnector {
pub confirmations: u64,
pub btc_light_client: AccountId,
pub mpc_signer: AccountId,
pub utxos: LookupSet<UTXO>,
pub utxos: Vector<UTXO>,
pub new_transfers: LookupMap<u64, NewTransferToBitcoin>,
pub min_nonce: u64,
pub last_nonce: u64,
@@ -91,7 +91,7 @@ impl BitcoinConnector {
confirmations,
btc_light_client,
mpc_signer,
utxos: LookupSet::new(StorageKey::UTXOs),
utxos: Vector::new(StorageKey::UTXOs),
new_transfers: LookupMap::new(StorageKey::NewTransfers),
min_nonce: 0,
last_nonce: 0,
@@ -134,7 +134,7 @@ impl BitcoinConnector {
Script::V0P2wpkh(pk) => {
if pk == self.bitcoin_pk {
value += tx_output.value;
self.utxos.insert(
self.utxos.push(
&UTXO {
txid: tx.tx_hash.clone(),
vout: i as u32,
@@ -162,6 +162,48 @@ impl BitcoinConnector {
.mint(recipient.parse().unwrap(), U128::from(value as u128));
}
}

pub fn sign(&mut self) {
let (unsigned_tx, utxos) = self.get_unsigned_tx();

}
}

impl BitcoinConnector {
fn get_unsigned_tx(&mut self) -> (Transaction, Vec<UTXO>) {
let utxos = self.get_utxos();
let new_transfer_data = self.new_transfers.get(&self.min_nonce).unwrap();
self.new_transfers.remove(&self.min_nonce);
self.min_nonce += 1;

let txin = TxIn {
previous_output: OutPoint {
txid: utxos[0].txid.clone(),
vout: utxos[0].vout.clone()
},
script_sig: vec![],
sequence: 0
};

let txout = TxOut {
value: new_transfer_data.value,
script_pubkey: Script::V0P2wpkh(new_transfer_data.recipient_on_bitcoin)
};

let unsigned_tx = Transaction {
version: 2,
lock_time: 0,
input: vec![txin],
output: vec![txout],
tx_hash: Default::default()
};

(unsigned_tx, utxos)
}

fn get_utxos(&mut self) -> Vec<UTXO> {
vec![self.utxos.pop().unwrap()]
}
}