Skip to content

Commit

Permalink
Adding full transfer method (#310)
Browse files Browse the repository at this point in the history
* Adding full transfer method

* Updating FullRgbTransferRequest struct

* Adding self pay to

* Bitcoin_inputs

* Match for btc_utxo

* Remove assert

* Full Transfer (PSBT + Dustless + Transfer)  (#312)

* refactor: add full transfer operation

* refactor: improviment psbt operation

* feat: add internal tests

* fix: improvement tests

* fix: coin selection

* fix: add btc change utxo

* fix: bitcoin derivation indexes

* Fix merge conflict.

* Add debug statement. Bump version to 0.6.3-rc.1.

* fix: genesis import and reduce esplora calls

* Bump bitmask-core to 0.6.3-rc.2.

* fix: blank transition for different contract types (#317)

* fix: watcher next utxos (#319)

* Bump bitmask-core to 0.6.3-rc.4.

* Not skipping is_spent in allocationdetail

* Adding watcher_unspent_utxos to web interface

* Switch to defaulting to blockstream Esplora API. Update to bitmask-core 0.6.3-rc.5.

* Tests are failing. Trying mempool.space API again.

* Update to using our own mempool instance.

* Configure to use our proxy to external mempool.

---------

Co-authored-by: Armando CD <[email protected]>
Co-authored-by: Hunter Trujillo <[email protected]>
Co-authored-by: Armando Dutra <[email protected]>
Co-authored-by: Hunter Beast <[email protected]>
  • Loading branch information
5 people authored Aug 6, 2023
1 parent 2291882 commit e792438
Show file tree
Hide file tree
Showing 22 changed files with 1,056 additions and 148 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ BITCOIN_ELECTRUM_API_MAINNET=18.217.213.66:50001
BITCOIN_ELECTRUM_API_TESTNET=18.217.213.66:60001
BITCOIN_ELECTRUM_API_SIGNET=18.217.213.66:60601
BITCOIN_ELECTRUM_API_REGTEST=localhost:50001
BITCOIN_EXPLORER_API_MAINNET=https://mempool.space/api
BITCOIN_EXPLORER_API_TESTNET=https://mempool.space/testnet/api
BITCOIN_EXPLORER_API_MAINNET=https://mempool.diba.io/api
BITCOIN_EXPLORER_API_TESTNET=https://mempool.diba.io/testnet/api
BITCOIN_EXPLORER_API_SIGNET=https://mutinynet.com/api
BITCOIN_EXPLORER_API_REGTEST=http://localhost:3000/regtest/api
# BITCOIN_EXPLORER_API_MAINNET=http://127.0.0.1:3000
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bitmask-core"
version = "0.6.2"
version = "0.6.3-rc.7"
authors = [
"Jose Diego Robles <[email protected]>",
"Hunter Trujillo <[email protected]>",
Expand Down
46 changes: 40 additions & 6 deletions src/bin/bitmaskd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{env, fs::OpenOptions, io::ErrorKind, net::SocketAddr, str::FromStr};
use amplify::hex::ToHex;
use anyhow::Result;
use axum::{
body::Bytes,
body::{Bytes, Full},
extract::Path,
headers::{authorization::Bearer, Authorization, CacheControl},
http::StatusCode,
Expand All @@ -21,15 +21,16 @@ use bitmask_core::{
constants::{get_marketplace_seed, get_network, get_udas_utxo, switch_network},
rgb::{
accept_transfer, clear_watcher as rgb_clear_watcher, create_invoice, create_psbt,
create_watcher, import as rgb_import, issue_contract, list_contracts, list_interfaces,
list_schemas, reissue_contract, transfer_asset, watcher_address,
create_watcher, full_transfer_asset, import as rgb_import, issue_contract, list_contracts,
list_interfaces, list_schemas, reissue_contract, transfer_asset, watcher_address,
watcher_details as rgb_watcher_details, watcher_next_address, watcher_next_utxo,
watcher_utxo,
},
structs::{
AcceptRequest, FileMetadata, ImportRequest, InvoiceRequest, IssueAssetRequest,
IssueRequest, MediaInfo, PsbtRequest, ReIssueRequest, RgbTransferRequest, SecretString,
SelfIssueRequest, SignPsbtRequest, WatcherRequest,
AcceptRequest, FileMetadata, FullRgbTransferRequest, ImportRequest, InvoiceRequest,
IssueAssetRequest, IssueRequest, MediaInfo, PsbtFeeRequest, PsbtRequest, ReIssueRequest,
RgbTransferRequest, SecretString, SelfFullRgbTransferRequest, SelfIssueRequest,
SignPsbtRequest, WatcherRequest,
},
};
use carbonado::file;
Expand Down Expand Up @@ -136,6 +137,38 @@ async fn pay(
Ok((StatusCode::OK, Json(transfer_res)))
}

#[axum_macros::debug_handler]
async fn self_pay(
Json(self_pay_req): Json<SelfFullRgbTransferRequest>,
) -> Result<impl IntoResponse, AppError> {
info!("POST /self_pay {self_pay_req:?}");

let issuer_keys = save_mnemonic(
&SecretString(get_marketplace_seed().await),
&SecretString("".to_string()),
)
.await?;

let sk = issuer_keys.private.nostr_prv.as_ref();

let fee = self_pay_req
.fee
.map_or(PsbtFeeRequest::Value(1000), PsbtFeeRequest::Value);

let request = FullRgbTransferRequest {
contract_id: self_pay_req.contract_id,
iface: self_pay_req.iface,
rgb_invoice: self_pay_req.rgb_invoice,
descriptor: SecretString(issuer_keys.public.rgb_udas_descriptor_xpub.clone()),
change_terminal: self_pay_req.terminal,
fee,
};

let transfer_res = full_transfer_asset(sk, request).await?;

Ok((StatusCode::OK, Json(transfer_res)))
}

async fn accept(
TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
Json(accept_req): Json<AcceptRequest>,
Expand Down Expand Up @@ -483,6 +516,7 @@ async fn main() -> Result<()> {
// .route("/psbt", post(psbt))
// .route("/sign", post(sign_psbt))
.route("/pay", post(pay))
.route("/selfpay", post(self_pay))
.route("/accept", post(accept))
.route("/contracts", get(contracts))
.route("/contract/:id", get(contract_detail))
Expand Down
Loading

0 comments on commit e792438

Please sign in to comment.