Skip to content

Commit e974ee1

Browse files
committed
rust: rename asset_tag to asset_id
Per the previous commit asset_tag is unused for single sig.
1 parent dd02648 commit e974ee1

File tree

5 files changed

+28
-28
lines changed

5 files changed

+28
-28
lines changed

subprojects/gdk_rust/gdk_common/src/model.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl ExchangeRateOk {
9090
pub struct AddressAmount {
9191
pub address: String, // could be bitcoin or elements
9292
pub satoshi: u64,
93-
pub asset_tag: Option<String>,
93+
pub asset_id: Option<String>,
9494
}
9595

9696
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
@@ -422,8 +422,8 @@ impl Default for Settings {
422422

423423
impl AddressAmount {
424424
pub fn asset(&self) -> Option<AssetId> {
425-
if let Some(asset_tag) = self.asset_tag.as_ref() {
426-
let vec = hex::decode(asset_tag).ok();
425+
if let Some(asset_id) = self.asset_id.as_ref() {
426+
let vec = hex::decode(asset_id).ok();
427427
if let Some(mut vec) = vec {
428428
vec.reverse();
429429
return (&vec[..]).try_into().ok();

subprojects/gdk_rust/gdk_electrum/src/account.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl Account {
189189
addressees.push(AddressAmount {
190190
address: address.unwrap_or_else(|| "".to_string()),
191191
satoshi: 0, // apparently not needed in list_tx addressees
192-
asset_tag: None,
192+
asset_id: None,
193193
});
194194
}
195195
}
@@ -731,7 +731,7 @@ pub fn create_tx(
731731

732732
let network = &account.network;
733733

734-
// TODO put checks into CreateTransaction::validate, add check asset_tag are valid asset hex
734+
// TODO put checks into CreateTransaction::validate, add check asset_id are valid asset hex
735735
// eagerly check for address validity
736736
for address in request.addressees.iter().map(|a| &a.address) {
737737
match network.id() {
@@ -793,7 +793,7 @@ pub fn create_tx(
793793
match network.id() {
794794
NetworkId::Bitcoin(_) => return Err(Error::InvalidAmount),
795795
NetworkId::Elements(_) => {
796-
if address_amount.asset_tag == network.policy_asset {
796+
if address_amount.asset_id == network.policy_asset {
797797
// we apply dust rules for liquid bitcoin as elements do
798798
return Err(Error::InvalidAmount);
799799
}
@@ -804,7 +804,7 @@ pub fn create_tx(
804804
}
805805

806806
if let NetworkId::Elements(_) = network.id() {
807-
if request.addressees.iter().any(|a| a.asset_tag.is_none()) {
807+
if request.addressees.iter().any(|a| a.asset_id.is_none()) {
808808
return Err(Error::AssetEmpty);
809809
}
810810
}
@@ -833,7 +833,7 @@ pub fn create_tx(
833833
if request.addressees.len() != 1 {
834834
return Err(Error::SendAll);
835835
}
836-
let asset = request.addressees[0].asset_tag.as_deref().unwrap_or("btc");
836+
let asset = request.addressees[0].asset_id.as_deref().unwrap_or("btc");
837837
let all_utxos: Vec<&(BEOutPoint, UTXOInfo)> =
838838
utxos.iter().filter(|(_, i)| i.asset == asset).collect();
839839
let total_amount_utxos: u64 = all_utxos.iter().map(|(_, i)| i.value).sum();
@@ -845,7 +845,7 @@ pub fn create_tx(
845845
}
846846
let out = &request.addressees[0]; // safe because we checked we have exactly one recipient
847847
dummy_tx
848-
.add_output(&out.address, out.satoshi, out.asset_tag.clone())
848+
.add_output(&out.address, out.satoshi, out.asset_id.clone())
849849
.map_err(|_| Error::InvalidAddress)?;
850850
// estimating 2 satoshi more as estimating less would later result in InsufficientFunds
851851
let estimated_fee = dummy_tx.estimated_fee(fee_rate, 0, account.script_type) + 2;
@@ -867,7 +867,7 @@ pub fn create_tx(
867867

868868
// STEP 1) add the outputs requested for this transactions
869869
for out in request.addressees.iter() {
870-
tx.add_output(&out.address, out.satoshi, out.asset_tag.clone())
870+
tx.add_output(&out.address, out.satoshi, out.asset_id.clone())
871871
.map_err(|_| Error::InvalidAddress)?;
872872
}
873873

subprojects/gdk_rust/gdk_electrum/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl Display for Error {
5454
Error::InvalidAmount => write!(f, "invalid amount"),
5555
Error::InvalidHeaders => write!(f, "invalid headers"),
5656
Error::EmptyAddressees => write!(f, "addressees cannot be empty"),
57-
Error::AssetEmpty => write!(f, "asset_tag cannot be empty in liquid"),
57+
Error::AssetEmpty => write!(f, "asset_id cannot be empty in liquid"),
5858
Error::InvalidSubaccount(sub) => write!(f, "invalid subaccount {}", sub),
5959
Error::AccountGapsDisallowed => {
6060
write!(f, "cannot create a new subaccount while the last one is unused")

subprojects/gdk_rust/tests/integration.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn liquid() {
8282
test_session.send_tx(&node_address, 10_000, Some(assets[0].clone()), None, None, None);
8383
test_session.send_tx(&node_address, 100, Some(assets[0].clone()), None, None, None); // asset should send below dust limit
8484
test_session.send_all(&node_address, Some(assets[0].to_string()));
85-
test_session.send_all(&node_address, test_session.asset_tag());
85+
test_session.send_all(&node_address, test_session.asset_id());
8686
test_session.mine_block();
8787
let assets = test_session.fund(100_000_000, Some(3));
8888
test_session.send_multi(3, 100_000, &vec![]);
@@ -336,7 +336,7 @@ fn labels() {
336336
create_opt.addressees.push(AddressAmount {
337337
address: test_session.get_receive_address(account2.account_num).address,
338338
satoshi: 50000,
339-
asset_tag: None,
339+
asset_id: None,
340340
});
341341
create_opt.memo = Some("Foo, Bar Foo".into());
342342
let tx = test_session.session.create_transaction(&mut create_opt).unwrap();

subprojects/gdk_rust/tests/test_session.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -352,14 +352,14 @@ impl TestSession {
352352
}
353353

354354
/// send all of the balance of the tx from the gdk session to the specified address
355-
pub fn send_all(&mut self, address: &str, asset_tag: Option<String>) {
356-
self.send_all_from_account(0, address, asset_tag);
355+
pub fn send_all(&mut self, address: &str, asset_id: Option<String>) {
356+
self.send_all_from_account(0, address, asset_id);
357357
}
358358
pub fn send_all_from_account(
359359
&mut self,
360360
subaccount: u32,
361361
address: &str,
362-
asset_tag: Option<String>,
362+
asset_id: Option<String>,
363363
) -> String {
364364
//let init_sat = self.balance_gdk();
365365
//let init_sat_addr = self.balance_addr(address);
@@ -370,7 +370,7 @@ impl TestSession {
370370
create_opt.addressees.push(AddressAmount {
371371
address: address.to_string(),
372372
satoshi: 0,
373-
asset_tag: asset_tag.clone(),
373+
asset_id: asset_id.clone(),
374374
});
375375
create_opt.send_all = Some(true);
376376
let tx = self.session.create_transaction(&mut create_opt).unwrap();
@@ -381,7 +381,7 @@ impl TestSession {
381381
self.wait_account_tx(subaccount, &txid);
382382
//let end_sat_addr = self.balance_addr(address);
383383
//assert_eq!(init_sat_addr + init_sat - tx.fee, end_sat_addr);
384-
assert_eq!(self.balance_account(subaccount, asset_tag, None), 0);
384+
assert_eq!(self.balance_account(subaccount, asset_id, None), 0);
385385

386386
assert!(tx.create_transaction.unwrap().send_all.unwrap());
387387
assert!(signed_tx.create_transaction.unwrap().send_all.unwrap());
@@ -409,7 +409,7 @@ impl TestSession {
409409
create_opt.addressees.push(AddressAmount {
410410
address: address.to_string(),
411411
satoshi,
412-
asset_tag: asset.clone().or(self.asset_tag()),
412+
asset_id: asset.clone().or(self.asset_id()),
413413
});
414414
create_opt.memo = memo;
415415
create_opt.utxos = unspent_outputs;
@@ -478,7 +478,7 @@ impl TestSession {
478478
create_opt.addressees.push(AddressAmount {
479479
address: address.to_string(),
480480
satoshi,
481-
asset_tag: asset.clone().or(self.asset_tag()),
481+
asset_id: asset.clone().or(self.asset_id()),
482482
});
483483
let tx = self.session.create_transaction(&mut create_opt).unwrap();
484484
let signed_tx = self.session.sign_transaction(&tx).unwrap();
@@ -551,7 +551,7 @@ impl TestSession {
551551
}
552552

553553
/// send a tx with multiple recipients with same amount from the gdk session to generated
554-
/// node's addressees, if `assets` contains values, they are used as asset_tag cyclically
554+
/// node's addressees, if `assets` contains values, they are used as asset_id cyclically
555555
pub fn send_multi(&mut self, recipients: u8, amount: u64, assets: &Vec<String>) {
556556
let init_sat = self.balance_gdk(None);
557557
let init_assets_sat = self.balance_gdk_all();
@@ -563,8 +563,8 @@ impl TestSession {
563563
let mut tags = vec![];
564564
for _ in 0..recipients {
565565
let address = self.node_getnewaddress(None);
566-
let asset_tag = if assets.is_empty() {
567-
self.asset_tag()
566+
let asset_id = if assets.is_empty() {
567+
self.asset_id()
568568
} else {
569569
let current = assets_cycle.next().unwrap().to_string();
570570
tags.push(current.clone());
@@ -574,7 +574,7 @@ impl TestSession {
574574
create_opt.addressees.push(AddressAmount {
575575
address: address.to_string(),
576576
satoshi: amount,
577-
asset_tag,
577+
asset_id,
578578
});
579579
addressees.push(address);
580580
}
@@ -656,7 +656,7 @@ impl TestSession {
656656
create_opt.addressees.push(AddressAmount {
657657
address: node_address.to_string(),
658658
satoshi: init_sat, // not enough to pay the fee with confidential utxos only
659-
asset_tag: self.asset_tag(),
659+
asset_id: self.asset_id(),
660660
});
661661
create_opt.confidential_utxos_only = Some(true);
662662
assert!(matches!(
@@ -708,7 +708,7 @@ impl TestSession {
708708
create_opt.addressees.push(AddressAmount {
709709
address: address.to_string(),
710710
satoshi,
711-
asset_tag: self.asset_tag(),
711+
asset_id: self.asset_id(),
712712
});
713713
let tx = self.session.create_transaction(&mut create_opt).unwrap();
714714
let signed_tx = self.session.sign_transaction(&tx).unwrap();
@@ -731,7 +731,7 @@ impl TestSession {
731731
create_opt.addressees.push(AddressAmount {
732732
address: address.to_string(),
733733
satoshi: 0,
734-
asset_tag: self.asset_tag(),
734+
asset_id: self.asset_id(),
735735
});
736736
assert!(matches!(
737737
self.session.create_transaction(&mut create_opt),
@@ -975,7 +975,7 @@ impl TestSession {
975975
Amount::from_btc(balance_btc).unwrap().as_sat()
976976
}
977977

978-
pub fn asset_tag(&self) -> Option<String> {
978+
pub fn asset_id(&self) -> Option<String> {
979979
match self.network_id {
980980
NetworkId::Bitcoin(_) => None,
981981
NetworkId::Elements(_) => self.network.policy_asset.clone(),

0 commit comments

Comments
 (0)