Skip to content

Commit

Permalink
funding and invoicing
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Dec 17, 2024
1 parent 6b192b9 commit f6db3da
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ bp-electrum = { git = "https://github.com/BP-WG/bp-electrum-client", branch = "v
bp-esplora = { git = "https://github.com/BP-WG/bp-esplora-client", branch = "v0.12" }
bp-wallet = { git = "https://github.com/BP-WG/bp-wallet", branch = "v0.12" }
rgb-core = { git = "https://github.com/RGB-WG/rgb-core", branch = "v0.12" }
rgb-std = { path = "../rgb-std" }
#rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.12" }
#rgb-std = { path = "../rgb-std" }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "v0.12" }

40 changes: 39 additions & 1 deletion cli/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use std::str::FromStr;
use amplify::ByteArray;
use bpwallet::fs::FsTextStore;
use bpwallet::psbt::TxParams;
use bpwallet::{Network, Sats, Vout, Wpkh, XpubDerivable};
use bpwallet::{Keychain, Network, Sats, Vout, Wpkh, XpubDerivable};
use clap::ValueHint;
use hypersonic::{AuthToken, ContractId};
use rgb::popls::bp::file::{DirBarrow, DirMound};
Expand Down Expand Up @@ -150,6 +150,23 @@ pub enum Cmd {
descriptor: String,
},

/// Receiving a wallet address for gas funding
Fund {
/// Wallet to use
#[clap(env = RGB_WALLET_ENV)]
wallet: Option<String>,
},

/// Generate a new single-use seal
Seal {
/// Wallet to use
#[clap(short, long, global = true, env = RGB_WALLET_ENV)]
wallet: Option<String>,

/// Nonce number to use
nonce: u64,
},

/// Print out a contract state
#[clap(alias = "s")]
State {
Expand Down Expand Up @@ -326,6 +343,27 @@ impl Args {
}
}

Cmd::Fund { wallet } => {
let mut runtime = self.runtime(wallet.as_deref());
let addr = match self.seal {
SealType::BitcoinOpret => {
runtime.wallet_opret().next_address(Keychain::OUTER, true)
}
SealType::BitcoinTapret => {
runtime.wallet_opret().next_address(Keychain::OUTER, true)
}
};
println!("{addr}");
}

Cmd::Seal { wallet, nonce } => {
let mut runtime = self.runtime(wallet.as_deref());
match runtime.auth_token(*nonce) {
None => println!("Wallet has no unspent outputs; try `fund` first"),
Some(token) => println!("{token}"),
}
}

Cmd::State {
wallet,
all,
Expand Down
2 changes: 1 addition & 1 deletion examples/Demo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ global:

owned:
- name: owned
seal: bee0be478fca7df9e8023357fe20a9e53058a178be9623afe3ac3400964bcf37:0
seal: b7116550736fbe5d3e234d0141c6bc8d1825f94da78514a3cede5674e9a5eae9:1
data: 10000
1 change: 1 addition & 0 deletions examples/data/bcor/alice/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ name = ""
[addrAnnotations]

[lastUsed]
0 = 2

[layer2]
142 changes: 142 additions & 0 deletions examples/data/bcor/bob/cache.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
lastBlock:
height: 1
time: 1231006505
blockHash: 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
lastChange: 0
headers: []
tx:
efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356:
txid: efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356
status: mempool
inputs:
- outpoint: d0455f0a1f4f8a699d33c78967d1285102568aaad84ee347787b18271503a400:0
payer: !counterparty tb1q0dzcgv7scppjxsnwlzpkt02vlmc5rtr40wyjgr
sequence: 4294967293
coinbase: false
scriptSig: ''
witness:
- 3044022009e5737120398635e8486023b133ea077c440e10a4b3cecb3bc97cd870ae7a77022026c3896b0c95cd5e9dd5217ee0f5f60ddf318dfd1c7c6fb2682906d527b078be01
- 030db9616d96a7b7a8656191b340f77e905ee2885a09a7a1e80b9c8b64ec746fb3
value: 94361040651
outputs:
- outpoint: efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356:0
beneficiary: !counterparty tb1q0dzcgv7scppjxsnwlzpkt02vlmc5rtr40wyjgr
value: 94361035510
spent: null
- outpoint: efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356:1
beneficiary: !wallet
addr: tb1qh397g85qrtwfrg2wv4u6lada3wdzdnykuqcsyr
terminal: '&0/1'
value: 5000
spent: null
fee: 141
size: 222
weight: 561
version: 2
locktime: 0
utxo:
- efb54853788df4a3ce31d7c74511f8d8c457e2e4b659773662e42d3bc5a44356:1
addr:
'0':
- terminal: '&0/0'
addr: tb1qufhxh8s93n29tqmks9vjfmesavstmggylaxsnw
used: 0
volume: 0
balance: 0
- terminal: '&0/1'
addr: tb1qh397g85qrtwfrg2wv4u6lada3wdzdnykuqcsyr
used: 1
volume: 5000
balance: 5000
- terminal: '&0/2'
addr: tb1qccx59nfgs2mndv32nvsk9j9w34txldp9crperf
used: 0
volume: 0
balance: 0
- terminal: '&0/3'
addr: tb1q5srksygehryp9p5t2av4zd8lj22a40una5gkah
used: 0
volume: 0
balance: 0
- terminal: '&0/4'
addr: tb1qc8u0fgd7atlg3zua77ej930xc4r4wc8r2cjyjr
used: 0
volume: 0
balance: 0
- terminal: '&0/5'
addr: tb1qk4rrzt6q2r2tc86urwxjsxqkzhs58cd02nyxmw
used: 0
volume: 0
balance: 0
- terminal: '&0/6'
addr: tb1qkvgk9sa5jaqc05qn5lt63rg54k9tyrwl2pctkk
used: 0
volume: 0
balance: 0
- terminal: '&0/7'
addr: tb1qcqzj6f5qulrqcw2j08m4j0est9nutfwr09eemm
used: 0
volume: 0
balance: 0
- terminal: '&0/8'
addr: tb1qqza7l77pndcnkxkq2750c72l7y0kx3w7v4xmt0
used: 0
volume: 0
balance: 0
- terminal: '&0/9'
addr: tb1q8pzl742785tke0sqy29lxntaqp0m6z5nsp6p59
used: 0
volume: 0
balance: 0
- terminal: '&0/10'
addr: tb1qxwa8jx6sllmq0zj00888xf08x2r0qgcv5qak66
used: 0
volume: 0
balance: 0
'1':
- terminal: '&1/0'
addr: tb1qhugqee7qw5fltp83ernxpl38l52mjywvn9mkkk
used: 0
volume: 0
balance: 0
- terminal: '&1/1'
addr: tb1ql8a9l7utw6kcrewzrzmry6wqcnxtmufr3dmms8
used: 0
volume: 0
balance: 0
- terminal: '&1/2'
addr: tb1qcq5xgz6prr9heu55r3ydy8t0tfgw6xgapyhdy0
used: 0
volume: 0
balance: 0
- terminal: '&1/3'
addr: tb1qge7w75zy7a99z4rfyhxjx6a4jxssxwdy7sq9au
used: 0
volume: 0
balance: 0
- terminal: '&1/4'
addr: tb1qs535dd5urn4jmnfqqrwrtyyelgyzhpg74v96hk
used: 0
volume: 0
balance: 0
- terminal: '&1/5'
addr: tb1qclqen4pz2gvnu0268wj3dn93ta4780th7uemlv
used: 0
volume: 0
balance: 0
- terminal: '&1/6'
addr: tb1q6wk9ngrh0vd30e5sp5zdjwwklkmhkxljjzn4rr
used: 0
volume: 0
balance: 0
- terminal: '&1/7'
addr: tb1qstpvrduxwu3wh0kn8mkvsxqxatj4uv3kuaxfvj
used: 0
volume: 0
balance: 0
- terminal: '&1/8'
addr: tb1qmp3mvxy07kztt5mwyw4asfa2l6kggyzh9p8yym
used: 0
volume: 0
balance: 0
layer2: {}
14 changes: 14 additions & 0 deletions examples/data/bcor/bob/data.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name = ""

[txAnnotations]

[txoutAnnotations]

[txinAnnotations]

[addrAnnotations]

[lastUsed]
0 = 3

[layer2]
10 changes: 10 additions & 0 deletions examples/data/bcor/bob/descriptor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
network = "testnet4"

[generator]
seals = []
noise = "b2594d09688565e0206593e720711eea03d560e38b491b4e3c66f9e3957aac86"

[generator.descr]
wpkh = "[cf05f8ea/84h/1h/1h]tpubDCpZeo9QAvMewp1ZhxjW25z3DSFC2eyt4wYimHuDNMkGzGhZsfUffCULroWTVUEfEaERv1rbbYPqG6fYb5Uivw86M3y4erJ7tGLRYcdbEFE/<0;1>/*"

[layer2]
Binary file added examples/data/bob.key
Binary file not shown.
1 change: 1 addition & 0 deletions examples/data/testnet4/alice
1 change: 1 addition & 0 deletions examples/data/testnet4/bob
1 change: 1 addition & 0 deletions examples/data/testnet4/bp.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaultWallet = "default"
2 changes: 2 additions & 0 deletions examples/script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ rm -rf examples/data/bcor/DemoToken.contract
$RGB --seal bcor issue -w alice examples/Demo.yaml
$RGB contracts
$RGB --seal bcor state -w alice
#$RGB --seal bcor fund alice
$RGB --seal bcor invoice alice 0
6 changes: 5 additions & 1 deletion src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

use amplify::Bytes32;
use bpstd::seals::Noise;
use bpstd::{Network, XpubDerivable};
use bpstd::{Network, Outpoint, XpubDerivable};
use bpwallet::{Layer2Empty, NoLayer2, Wallet, WalletCache, WalletData, WalletDescr};
use nonasync::persistence::{PersistenceError, PersistenceProvider};
use rgb::popls::bp::{OpretProvider, TapretProvider, WalletProvider};
Expand All @@ -39,6 +39,8 @@ pub struct OpretWallet(Wallet<XpubDerivable, Opret<XpubDerivable>, NoLayer2>);

impl WalletProvider for OpretWallet {
fn noise_seed(&self) -> Bytes32 { self.noise }

fn utxos(&self) -> impl Iterator<Item = Outpoint> { self.0.utxos().map(|utxo| utxo.outpoint) }
}
impl OpretProvider for OpretWallet {}

Expand Down Expand Up @@ -80,6 +82,8 @@ pub struct TapretWallet(Wallet<XpubDerivable, Tapret<XpubDerivable>, NoLayer2>);

impl WalletProvider for TapretWallet {
fn noise_seed(&self) -> Bytes32 { self.noise }

fn utxos(&self) -> impl Iterator<Item = Outpoint> { self.0.utxos().map(|utxo| utxo.outpoint) }
}
impl TapretProvider for TapretWallet {}

Expand Down

0 comments on commit f6db3da

Please sign in to comment.