Skip to content

Commit

Permalink
Fix failure for DefineAsset and IssueAsset operation sent in same txn
Browse files Browse the repository at this point in the history
The DefineAsset Operation has the raw asset code whereas IssueAsset Operation
has the derived asset code.

Currently if both the operations are sent in the same txn for a new asset it fails
because the Asset code don't match. This is fixed by comparing the derived asset
code from newly defined assets in the txn.
  • Loading branch information
harshadptl committed Oct 13, 2023
1 parent 7b043ec commit 3f9cc6a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/ledger/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,20 @@ impl LedgerStatus {
// Asset issuance should match the currently registered key
}

let get_effect_asset = |derived_asset_code: &AssetTypeCode| -> Option<AssetType> {
for (code, asset) in &txn_effect.new_asset_codes {
let dc = AssetTypeCode::from_prefix_and_raw_asset_type_code(
AssetTypePrefix::UserDefined,
&code,
&CFG.checkpoint,
self.td_commit_height,
);
if dc == *derived_asset_code {
return Some(asset.clone())
}
}
return None
};
// New issuance numbers
// (1) Must refer to a created asset type
// - NOTE: if the asset type is created in this transaction, this
Expand All @@ -1560,7 +1574,7 @@ impl LedgerStatus {
let asset_type = self
.asset_types
.get(&code)
.or_else(|| txn_effect.new_asset_codes.get(&code).cloned())
.or_else(|| get_effect_asset(&code))
.c(d!())?;
let proper_key = asset_type.properties.issuer;
if *iss_key != proper_key {
Expand Down

0 comments on commit 3f9cc6a

Please sign in to comment.