Skip to content

Commit 3c08359

Browse files
authored
fix: allow setting of tokens balances on InterimContractChanges (propeller-heads#139)
1 parent ad0a391 commit 3c08359

File tree

1 file changed

+16
-0
lines changed
  • substreams/crates/tycho-substreams/src

1 file changed

+16
-0
lines changed

substreams/crates/tycho-substreams/src/models.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,22 @@ impl InterimContractChange {
515515
self.code.clear();
516516
self.code.extend_from_slice(code);
517517
}
518+
519+
pub fn upsert_token_balance(&mut self, token: &[u8], balance: &[u8]) {
520+
self.token_balances
521+
.entry(token.to_vec())
522+
.and_modify(|b| {
523+
b.clear();
524+
b.extend_from_slice(balance);
525+
})
526+
.or_insert_with(|| balance.to_vec());
527+
}
528+
529+
pub fn upsert_token_balances(&mut self, balances: &HashMap<Vec<u8>, Vec<u8>>) {
530+
for (token, balance) in balances.iter() {
531+
self.upsert_token_balance(token, balance);
532+
}
533+
}
518534
}
519535

520536
impl From<InterimContractChange> for Option<ContractChange> {

0 commit comments

Comments
 (0)