Skip to content

Commit

Permalink
Merge pull request #2 from AmAzing129/fix/example
Browse files Browse the repository at this point in the history
fix: modify readme and add an example
  • Loading branch information
jeasonstudio committed May 8, 2024
2 parents c44b942 + 99c175c commit 9be2e82
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 42 deletions.
70 changes: 35 additions & 35 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import { Runestone, Transaction } from '@ordjs/runestone';
const tx: Transaction = {
output: [{
// // OP_RETURN OP_PUSHNUM_13 ...
script_pubkey: '6a5d1f02010480bbb180c5ddf4ede90303a40805b5e9070680809dd085bedd031601',
script_pubkey: '6a5d21020704b5e1d8e1c8eeb788a30705a02d039f3e01020680dc9afd2808c7e8430a64',
value: 0,
}],
};
Expand Down
2 changes: 1 addition & 1 deletion documents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import { Runestone, Transaction } from '@ordjs/runestone';
const tx: Transaction = {
output: [{
// // OP_RETURN OP_PUSHNUM_13 ...
script_pubkey: '6a5d1f02010480bbb180c5ddf4ede90303a40805b5e9070680809dd085bedd031601',
script_pubkey: '6a5d21020704b5e1d8e1c8eeb788a30705a02d039f3e01020680dc9afd2808c7e8430a64',
value: 0,
}],
};
Expand Down
8 changes: 4 additions & 4 deletions documents/interfaces/Transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#### Defined in

index.d.ts:27
index.d.ts:23

___

Expand All @@ -29,7 +29,7 @@ ___

#### Defined in

index.d.ts:26
index.d.ts:22

___

Expand All @@ -39,7 +39,7 @@ ___

#### Defined in

index.d.ts:28
index.d.ts:24

___

Expand All @@ -49,4 +49,4 @@ ___

#### Defined in

index.d.ts:25
index.d.ts:21
2 changes: 1 addition & 1 deletion documents/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#### Defined in

index.d.ts:21
index.d.ts:28

## Functions

Expand Down
62 changes: 62 additions & 0 deletions examples/decipher.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Decipher Runes</title>
<style>
#input {
width: 500px;
}
</style>
</head>
<body>
<h1>Please input the transaction hash</h1>
<input id="input" />
<button onclick="decipher()">decipher message</button>
<h1>Results</h1>
<div id="content"></div>
</body>
<script type="module">
import { Runestone } from "https://esm.sh/@ordjs/runestone/bundle";

async function getTx(txid) {
const tx = await fetch(`https://mempool.space/api/tx/${txid}`).then(
(res) => res.json()
);
return tx;
}

function getOutputTx(tx) {
const output = tx.vout.map((o) =>
replacePropertyName(o, "scriptpubkey", "script_pubkey")
);
return {
output,
};
}

function replacePropertyName(obj, oldName, newName) {
if (!obj.hasOwnProperty(oldName)) return;
let newObj = { ...obj };
newObj[newName] = newObj[oldName];
delete newObj[oldName];
return newObj;
}

async function decipher() {
document.getElementById("content").innerText = "waiting...";
const txid = document.getElementById("input").value;
const tx = await getTx(txid);
const outputTx = getOutputTx(tx);
try {
const runestone = Runestone.decipher(outputTx);
document.getElementById("content").innerText =
JSON.stringify(runestone);
} catch {
document.getElementById("content").innerText = "error";
}
}

window.decipher = decipher;
</script>
</html>

0 comments on commit 9be2e82

Please sign in to comment.