Last active
June 15, 2022 21:41
-
-
Save valstu/d2aef31e43c007e2c5dabb24051589bc 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
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 = '{{ notary_account }}'; | |
// Bob | |
const proposer_secret = '{{ proposer_secret }}'; | |
const proposer_account = '{{ proposer_account }}'; | |
const proposer_keypair = lib.derive.familySeed(proposer_secret); | |
const client = new XrplClient('wss://hooks-testnet-v2.xrpl-labs.com'); | |
const main = async () => { | |
console.log('notary_account', notary_account); | |
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() |
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
import lib from "https://esm.sh/xrpl-accountlib?bundle"; | |
import { XrplClient } from "https://esm.sh/xrpl-client?bundle"; | |
// Alice | |
const notary_account = '{{ notary_account }}'; | |
// Carol | |
const approver_secret = '{{ approver_secret }}'; | |
const approver_account = '{{ approver_account }}'; | |
const approver_keypair = lib.derive.familySeed(approver_secret); | |
const client = new XrplClient('wss://hooks-testnet-v2.xrpl-labs.com'); | |
const main = async (proposal) => { | |
console.log("proposal", proposal); | |
try { | |
const { account_data } = await client.send({ command: 'account_info', 'account': approver_account }); | |
if (!account_data) { | |
console.log('Approver account not found.'); | |
client.close(); | |
return; | |
} | |
console.log("sequence", account_data.Sequence); | |
const tx = { | |
Account: approver_account, | |
TransactionType: "Payment", | |
Amount: "1", | |
Destination: notary_account, | |
Fee: "1000000", | |
InvoiceID: proposal, | |
Sequence: account_data.Sequence | |
}; | |
const {signedTransaction} = lib.sign(tx, approver_keypair); | |
const submit = await client.send({ command: 'submit', 'tx_blob': signedTransaction }); | |
console.log(submit); | |
} catch (err) { | |
console.error(err) | |
} | |
console.log('Shutting down...'); | |
client.close(); | |
}; | |
main("{{InvoiceID}}"); |
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
/** | |
* This hook just accepts any transaction coming through it | |
*/ | |
#include "hookapi.h" | |
int64_t cbak(uint32_t reserved) { | |
return 0; | |
} | |
int64_t hook(uint32_t reserved ) { | |
TRACESTR("Accept.c: Called."); | |
accept (0,0,0); | |
_g(1,1); // every hook needs to import guard function and use it at least once | |
// unreachable | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment