11use std:: { collections:: BTreeMap , ops:: Mul , str:: FromStr } ;
22
3- use amplify:: { confinement:: Confined , hex:: FromHex } ;
3+ use amplify:: {
4+ confinement:: { Confined , U32 } ,
5+ hex:: FromHex ,
6+ } ;
47use baid58:: ToBaid58 ;
58use bech32:: { decode, FromBase32 } ;
69use bitcoin:: Network ;
@@ -9,12 +12,13 @@ use garde::Validate;
912use rand:: { rngs:: StdRng , Rng , SeedableRng } ;
1013use rgb:: { RgbWallet , TerminalPath } ;
1114use rgbstd:: {
15+ containers:: { Bindle , Consignment } ,
1216 contract:: ContractId ,
1317 interface:: TypedState ,
1418 persistence:: { Inventory , Stash , Stock } ,
1519} ;
1620use rgbwallet:: RgbInvoice ;
17- use strict_encoding:: tn ;
21+ use strict_encoding:: { tn , StrictSerialize } ;
1822
1923use crate :: {
2024 bitcoin:: get_swap_new_address,
@@ -45,6 +49,8 @@ use crate::rgb::{
4549 RgbSwapError , SaveTransferError , TransferError ,
4650} ;
4751
52+ use super :: transfer:: extract_bindle;
53+
4854pub const DUST_LIMIT_SATOSHI : u64 = 546 ;
4955
5056pub async fn prebuild_transfer_asset (
@@ -863,38 +869,73 @@ pub async fn prebuild_buyer_swap(
863869pub fn prebuild_extract_transfer (
864870 consignment : & str ,
865871) -> Result < RgbExtractTransfer , SaveTransferError > {
872+ let mut is_armored = false ;
866873 let serialized = if consignment. starts_with ( "rgb1" ) {
867874 let ( _, serialized, _) =
868875 decode ( consignment) . expect ( "invalid serialized contract/genesis (bech32m format)" ) ;
869876 Vec :: < u8 > :: from_base32 ( & serialized)
870877 . expect ( "invalid hexadecimal contract/genesis (bech32m format)" )
878+ } else if consignment. starts_with ( "-----" ) {
879+ is_armored = true ;
880+ Vec :: new ( )
871881 } else {
872882 Vec :: < u8 > :: from_hex ( consignment) . expect ( "invalid hexadecimal contract/genesis" )
873883 } ;
874884
875- let confined = Confined :: try_from_iter ( serialized. iter ( ) . copied ( ) )
876- . expect ( "invalid confined serialization" ) ;
877- let ( tx_id, transfer, offer_id, bid_id) = match extract_transfer ( consignment. to_owned ( ) ) {
878- Ok ( ( txid, tranfer) ) => ( txid, tranfer, None , None ) ,
879- _ => match extract_swap_transfer ( consignment. to_owned ( ) ) {
880- Ok ( ( txid, tranfer, offer_id, bid_id) ) => (
881- txid,
882- tranfer,
883- Some ( offer_id. to_baid58_string ( ) ) ,
884- Some ( bid_id. to_baid58_string ( ) ) ,
885- ) ,
886- Err ( err) => return Err ( SaveTransferError :: WrongConsigSwap ( err) ) ,
887- } ,
888- } ;
885+ if is_armored {
886+ let transfer =
887+ Bindle :: < Consignment < true > > :: from_str ( consignment) . expect ( "bindle parse error" ) ; // ?;
888+
889+ let confined = transfer. to_strict_serialized :: < U32 > ( ) ?;
890+
891+ let ( tx_id, transfer, offer_id, bid_id) = match extract_bindle ( transfer) {
892+ Ok ( ( txid, transfer) ) => ( txid, transfer, None , None ) ,
893+ _ => match extract_swap_transfer ( consignment. to_owned ( ) ) {
894+ Ok ( ( txid, transfer, offer_id, bid_id) ) => (
895+ txid,
896+ transfer,
897+ Some ( offer_id. to_baid58_string ( ) ) ,
898+ Some ( bid_id. to_baid58_string ( ) ) ,
899+ ) ,
900+ Err ( err) => return Err ( SaveTransferError :: WrongConsigSwap ( err) ) ,
901+ } ,
902+ } ;
889903
890- let contract_id = transfer. contract_id ( ) . to_string ( ) ;
891- Ok ( RgbExtractTransfer {
892- consig_id : transfer. id ( ) . to_string ( ) ,
893- contract_id,
894- tx_id,
895- transfer,
896- offer_id,
897- bid_id,
898- strict : confined,
899- } )
904+ let contract_id = transfer. contract_id ( ) . to_string ( ) ;
905+ Ok ( RgbExtractTransfer {
906+ consig_id : transfer. id ( ) . to_string ( ) ,
907+ contract_id,
908+ tx_id,
909+ transfer,
910+ offer_id,
911+ bid_id,
912+ strict : confined,
913+ } )
914+ } else {
915+ let confined = Confined :: try_from_iter ( serialized. iter ( ) . copied ( ) )
916+ . expect ( "invalid confined serialization" ) ;
917+ let ( tx_id, transfer, offer_id, bid_id) = match extract_transfer ( consignment. to_owned ( ) ) {
918+ Ok ( ( txid, transfer) ) => ( txid, transfer, None , None ) ,
919+ _ => match extract_swap_transfer ( consignment. to_owned ( ) ) {
920+ Ok ( ( txid, transfer, offer_id, bid_id) ) => (
921+ txid,
922+ transfer,
923+ Some ( offer_id. to_baid58_string ( ) ) ,
924+ Some ( bid_id. to_baid58_string ( ) ) ,
925+ ) ,
926+ Err ( err) => return Err ( SaveTransferError :: WrongConsigSwap ( err) ) ,
927+ } ,
928+ } ;
929+
930+ let contract_id = transfer. contract_id ( ) . to_string ( ) ;
931+ Ok ( RgbExtractTransfer {
932+ consig_id : transfer. id ( ) . to_string ( ) ,
933+ contract_id,
934+ tx_id,
935+ transfer,
936+ offer_id,
937+ bid_id,
938+ strict : confined,
939+ } )
940+ }
900941}
0 commit comments