-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,96 @@ | ||
use super::*; | ||
|
||
// TODO: | ||
// - [ ] add a --dry-run flag that doesn't sign our inputs in the PSBT | ||
// - [ ] pub fee: u64, | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct Output { | ||
pub psbt: String, | ||
pub seller_address: Address<NetworkUnchecked>, | ||
pub inscription: InscriptionId, | ||
} | ||
|
||
#[derive(Debug, Parser)] | ||
pub(crate) struct Create { | ||
#[arg(short, long, help = "<INSCRIPTION> to make offer for.")] | ||
#[arg(long, help = "<INSCRIPTION> to make offer for.")] | ||
inscription: InscriptionId, | ||
#[arg(long, help = "<AMOUNT> to offer.")] | ||
amount: Amount, | ||
#[arg(long, help = "<FEE_RATE> for finalized transaction.")] | ||
fee_rate: FeeRate, | ||
} | ||
|
||
impl Create { | ||
pub(crate) fn run(&self, wallet: Wallet) -> SubcommandResult { | ||
todo!() | ||
ensure!( | ||
!wallet.inscription_info().contains_key(&self.inscription), | ||
"{} in our wallet", | ||
self.inscription | ||
); | ||
|
||
let inscription = wallet.get_inscription(self.inscription)?; | ||
|
||
let utxo = inscription.satpoint.outpoint; | ||
|
||
let Some(seller_address) = inscription.address else { | ||
bail!("{} not owned by an address", self.inscription); | ||
}; | ||
|
||
let Ok(seller_address) = Address::from_str(&seller_address) else { | ||
bail!("{} not owned by an usable address", self.inscription); | ||
}; | ||
|
||
let unsigned_transaction = Transaction { | ||
version: Version(2), | ||
lock_time: LockTime::ZERO, | ||
input: vec![TxIn { | ||
previous_output: utxo, | ||
script_sig: ScriptBuf::new(), | ||
sequence: Sequence::ENABLE_RBF_NO_LOCKTIME, | ||
witness: Witness::new(), | ||
}], | ||
output: vec![ | ||
TxOut { | ||
value: Amount::from_sat(inscription.value.unwrap()), | ||
script_pubkey: wallet.get_change_address()?.into(), | ||
}, | ||
TxOut { | ||
value: self.amount, | ||
script_pubkey: seller_address | ||
.clone() | ||
.require_network(wallet.chain().network()) | ||
.unwrap() | ||
.into(), | ||
}, | ||
], | ||
}; | ||
|
||
let unsigned_transaction_hex = fund_raw_transaction( | ||
wallet.bitcoin_client(), | ||
self.fee_rate, | ||
&unsigned_transaction, | ||
)?; | ||
|
||
let unsigned_transaction = | ||
Transaction::consensus_decode(&mut unsigned_transaction_hex.as_slice())?; | ||
|
||
let unsigned_psbt = Psbt::from_unsigned_tx(unsigned_transaction)?; | ||
|
||
let psbt = wallet | ||
.bitcoin_client() | ||
.wallet_process_psbt( | ||
&base64::engine::general_purpose::STANDARD.encode(unsigned_psbt.serialize()), | ||
Some(true), | ||
None, | ||
None, | ||
)? | ||
.psbt; | ||
|
||
Ok(Some(Box::new(Output { | ||
psbt, | ||
inscription: self.inscription, | ||
seller_address, | ||
}))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters