Created
June 13, 2022 13:24
-
-
Save valstu/e848b4787326563208f181bde613e9d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="module"> | |
import lib from "https://esm.sh/xrpl-accountlib?bundle"; | |
import bin from "https://esm.sh/ripple-binary-codec?bundle"; | |
import { XrplClient } from "https://esm.sh/xrpl-client?bundle"; | |
// Alice | |
const notary_account = "ssf"; | |
// Bob | |
const proposer_secret = "aa"; | |
const proposer_account = "ss"; | |
const proposer_keypair = lib.derive.familySeed(proposer_secret); | |
const client = new XrplClient("wss://hooks-testnet-v2.xrpl-labs.com"); | |
const main = async () => { | |
console.log("Getting ready..."); | |
const proposed_tx = { | |
TransactionType: "Payment", | |
Account: notary_account, | |
Amount: "100", | |
Destination: proposer_account, | |
DestinationTag: "42", | |
LastLedgerSequence: "4000000000", | |
// Fee: '1200000' | |
Fee: "0", | |
Sequence: 0, | |
}; | |
const inner_tx = bin.encode(proposed_tx); | |
const { account_data } = await client.send({ | |
command: "account_info", | |
account: proposer_account, | |
}); | |
if (!account_data) { | |
console.log("Proposer account not found."); | |
client.close(); | |
return; | |
} | |
console.log("sequence", account_data.Sequence); | |
const tx = { | |
TransactionType: "Payment", | |
Account: proposer_account, | |
Amount: "1", | |
Destination: notary_account, | |
Fee: "12000000", | |
Memos: [ | |
{ | |
Memo: { | |
MemoData: inner_tx, | |
MemoFormat: "unsigned/payload+1", | |
MemoType: "notary/proposed", | |
}, | |
}, | |
], | |
Sequence: account_data.Sequence, | |
}; | |
hexlify_memos(tx); | |
const { signedTransaction } = lib.sign(tx, proposer_keypair); | |
const submit = await client.send({ | |
command: "submit", | |
tx_blob: signedTransaction, | |
}); | |
console.log(submit); | |
console.log("Shutting down..."); | |
client.close(); | |
}; | |
function hexlify_memos(x) { | |
if (!("Memos" in x)) return; | |
for (y in x["Memos"]) { | |
for (a in x["Memos"][y]) { | |
let Fields = ["MemoFormat", "MemoType", "MemoData"]; | |
for (z in Fields) { | |
if (Fields[z] in x["Memos"][y][a]) { | |
let u = x["Memos"][y][a][Fields[z]].toUpperCase(); | |
if (u.match(/^[0-9A-F]+$/)) { | |
x["Memos"][y][a][Fields[z]] = u; | |
continue; | |
} | |
x["Memos"][y][a][Fields[z]] = | |
"" + | |
Buffer.from(x["Memos"][y][a][Fields[z]]) | |
.toString("hex") | |
.toUpperCase(); | |
} | |
} | |
} | |
} | |
} | |
main(); | |
</script> | |
</head> | |
<body> | |
kissa | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment