-
Notifications
You must be signed in to change notification settings - Fork 0
Substitution of UTXO transaction ID in the template #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: omni-main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -40,8 +40,9 @@ impl Contract { | |||||||
&self, | ||||||||
deposit_msg: DepositMsg, | ||||||||
actual_mintable_amount: u128, | ||||||||
utxo_tx_id: String, | ||||||||
) -> Option<Vec<PostAction>> { | ||||||||
let post_actions = deposit_msg.post_actions?; | ||||||||
let mut post_actions = deposit_msg.post_actions?; | ||||||||
if post_actions.is_empty() { | ||||||||
Event::InvalidPostAction { | ||||||||
index: None, | ||||||||
|
@@ -65,7 +66,7 @@ impl Contract { | |||||||
} | ||||||||
let mut total_gas = 0; | ||||||||
let mut total_amount = 0; | ||||||||
for (index, post_action) in post_actions.iter().enumerate() { | ||||||||
for (index, post_action) in post_actions.iter_mut().enumerate() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think the changes can be done with less code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we can do it this way, it’s really the simplest option. In that case, the replacement will always happen regardless of what is specified in the templates. I also thought about adding a special template like 'add UTXO', and if such a template exists, then perform the replacement. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think about something like that: I’d like to isolate the contracts to which the changes are applied. In this option, the code is simpler. However, the logic becomes stranger. Templates stop being templates and turn into modifiers. The first option sounds more logical in the context of templates. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also thought that it is important to add additional restrictions, but after thinking more on it, I think we can make things simple and just do replace. |
||||||||
total_amount += post_action.amount.0; | ||||||||
// The receiver_id must be on the whitelist. | ||||||||
if !self | ||||||||
|
@@ -88,21 +89,41 @@ impl Contract { | |||||||
.post_action_msg_templates | ||||||||
.get(&post_action.receiver_id) | ||||||||
{ | ||||||||
let is_match = | ||||||||
let updated_post_action: Option<String> = | ||||||||
match serde_json::from_str::<Value>(&post_action.msg) { | ||||||||
Ok(msg_value) => msg_templates.iter().any(|template| { | ||||||||
match serde_json::from_str::<Value>(template) { | ||||||||
Ok(template_value) => { | ||||||||
is_structure_equal(&template_value, &msg_value) | ||||||||
Ok(msg_value) => { | ||||||||
let mut res = None; | ||||||||
for template in msg_templates { | ||||||||
if let Ok(template_value) = serde_json::from_str::<Value>(template) | ||||||||
{ | ||||||||
res = check_template_and_update_msg( | ||||||||
&template_value, | ||||||||
&msg_value, | ||||||||
&utxo_tx_id, | ||||||||
); | ||||||||
if res.is_some() { | ||||||||
break; | ||||||||
} | ||||||||
} | ||||||||
Err(_) => false, | ||||||||
} | ||||||||
}), | ||||||||
Err(_) => msg_templates | ||||||||
.iter() | ||||||||
.any(|template| template == &post_action.msg), | ||||||||
|
||||||||
res.map(|x| x.to_string()) | ||||||||
} | ||||||||
Err(_) => { | ||||||||
if msg_templates | ||||||||
.iter() | ||||||||
.any(|template| template == &post_action.msg) | ||||||||
{ | ||||||||
Some(post_action.msg.clone()) | ||||||||
} else { | ||||||||
None | ||||||||
} | ||||||||
} | ||||||||
}; | ||||||||
if !is_match { | ||||||||
|
||||||||
if let Some(updated_post_action) = updated_post_action { | ||||||||
post_action.msg = updated_post_action; | ||||||||
} else { | ||||||||
Event::InvalidPostAction { | ||||||||
index: Some(index), | ||||||||
err_msg: "Unsupported post_action.msg.".to_string(), | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that the
tx_id
is unique?As I see it is possible to
verify_deposit
with differentvout
for same transactionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed: 3293a0e