Skip to content

Commit

Permalink
more gracefully handle memos that dont parse
Browse files Browse the repository at this point in the history
  • Loading branch information
willemolding committed Jun 6, 2024
1 parent 406f58b commit 0768ac3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ run-local:
run-fullnode:
cargo run --no-default-features --features listen-graphql,lightwalletd

run-fullnode-testnet:
ROLLUP_HTTP_SERVER_URL=https://cartezcash.fly.dev/graphql cargo run --no-default-features --features listen-graphql,lightwalletd

run-nobackend:
cartesi run --no-backend --epoch-duration=10

Expand Down
18 changes: 10 additions & 8 deletions src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ impl From<tiny_cash::service::Response> for Response {
withdrawals: res
.burns
.iter()
.map(|(amount, memo)| {
let addres_bytes = hex::decode(&memo.0[0..40]) // expect unicode hex no 0x prefix (inefficient). skip the version byte at the start
.expect("failed to decode memo");

(
ethereum_types::Address::from_slice(&addres_bytes),
ethereum_types::U256::from(amount.zatoshis()),
)
.filter_map(|(amount, memo)| {
if let Ok(address_bytes) = hex::decode(&memo.0[0..40]) { // expect unicode hex no 0x prefix (inefficient). skip the version byte at the start
Some((
ethereum_types::Address::from_slice(&address_bytes),
ethereum_types::U256::from(amount.zatoshis()),
))
} else {
tracing::debug!("failed to decode address from burn memo {:?}. Skipping withdrawal.", memo.0);
None
}
})
.collect(),
block: res.block,
Expand Down

0 comments on commit 0768ac3

Please sign in to comment.