Skip to content

Commit

Permalink
Use SnapshotConfirmed instead of TxValid
Browse files Browse the repository at this point in the history
  • Loading branch information
noonio committed Oct 8, 2024
1 parent 6b955ac commit a125d9b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions hydraw/static/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ let n = 0
client.addEventListener("message", e => {
const msg = JSON.parse(e.data);
switch (msg.tag) {
case "TxValid":
// TODO: Should only draw pixels on SnapshotConfirmed
const cborHex = msg.transaction.cborHex;
console.log("New transaction cborHex seen", cborHex);
const transaction = cbor.decodeFirstSync(cborHex);
const auxiliaryData = transaction[3]
if (auxiliaryData !== undefined && auxiliaryData !== null) {
console.log("Transaction has auxiliary data", auxiliaryData);
const aux = auxiliaryData.value;
const [x, y, r, g, b] = (aux.get(0) || aux.get(1)).get(metadataLabel);
n += delay;
setTimeout(() => drawPixel(x, y, [r, g, b]), n);
}
case "SnapshotConfirmed":
msg.snapshot.confirmed.forEach( (tx, _) => {
const cborHex = tx.cborHex;
console.log("New confirmed transaction cborHex seen", cborHex);
const transaction = cbor.decodeFirstSync(cborHex);
const auxiliaryData = transaction[3]
if (auxiliaryData !== undefined && auxiliaryData !== null) {
console.log("Transaction has auxiliary data", auxiliaryData);
const aux = auxiliaryData.value;
const [x, y, r, g, b] = (aux.get(0) || aux.get(1)).get(metadataLabel);
n += delay;
setTimeout(() => drawPixel(x, y, [r, g, b]), n);
}
})
default:
console.log("Irrelevant message", msg);
}
Expand Down

0 comments on commit a125d9b

Please sign in to comment.