Checks - JS Bounty (#1705)

This commit is contained in:
Tushar Pardhe
2023-02-08 00:39:10 +00:00
committed by GitHub
parent 627b5e2730
commit 5ec2e61e54
5 changed files with 201 additions and 1 deletions

View File

@@ -0,0 +1,44 @@
const xrpl = require('xrpl');
const secret = "sEdTPPEeMH6SAgpo6rSj8YW7a9vFfUj"; // TODO: Replace with your secret
const checkId = ""; // TODO: Replace with your check ID
const main = async ()=> {
try {
// Connect ----------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
// Check if the check ID is provided --------------------------------------
if (checkId.length === 0) {
console.log("Please edit this snippet to provide a check ID. You can get a check ID by running create_check.js.");
return;
}
// Prepare ----------------------------------------------------------------
const wallet = await xrpl.Wallet.fromSeed(secret);
console.log("Wallet address: ", wallet.address);
const checkCancelRequest = {
"TransactionType": "CheckCancel",
"Account": wallet.address,
"CheckID": checkId
};
// Auto-fill the fields ---------------------------------------------------
const prepared = await client.autofill(checkCancelRequest);
// Submit -----------------------------------------------------------------
const response = await client.submitAndWait(prepared, { wallet });
console.log(JSON.stringify(response.result, null, "\t"));
// Disconnect -------------------------------------------------------------
await client.disconnect();
} catch (error) {
console.error(`Error: ${error}`);
}
}
main();

View File

@@ -0,0 +1,43 @@
'use strict'
const xrpl = require('xrpl');
const secret = "sEdTPPEeMH6SAgpo6rSj8YW7a9vFfUj"; // TODO: Replace with your secret
const checkId = ""; // TODO: Replace with your check ID
const amount = "12"; // TODO: Replace with the amount you want to cash
const main = async () => {
try {
// Connect to the testnet
const client = new xrpl.Client("wss://s.altnet.rippletest.net:51233");
await client.connect();
// Generate a wallet ------------------------------------------------------
const wallet = await xrpl.Wallet.fromSeed(secret);
console.log("Wallet address: ", wallet.address);
// Check if the check ID is provided --------------------------------------
if (checkId.length === 0) {
console.log("Please edit this snippet to provide a check ID. You can get a check ID by running create_check.js.");
return;
}
// Prepare the transaction ------------------------------------------------
const transaction = {
TransactionType: "CheckCash",
Account: wallet.address,
CheckID: checkId,
Amount: amount,
};
// Submit -----------------------------------------------------------------
const response = await client.submitAndWait(transaction, { wallet });
console.log(JSON.stringify(response.result, null, "\t"));
// Disconnect -------------------------------------------------------------
await client.disconnect();
} catch (error) {
console.log("Error: ", error);
}
}
main()

View File

@@ -0,0 +1,57 @@
'use strict'
const xrpl = require('xrpl');
const crypto = require('crypto');
const hash = crypto.createHash('sha512');
// Destination address for the check
const destination = "rP2BPdQ9ANSK7kVWT9jkjjDxCxL7xrC7oD";
// Amount of XRP in drops to send
const amount = "10000000";
const main = async () => {
try {
// Connect to the XRP Ledger Test Net -------------------------------------
console.log("Connecting to Test Net...");
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
console.log("Connected to Test Net");
// Generating new wallet --------------------------------------------------
console.log("Generating new wallet...");
const { wallet } = await client.fundWallet();
console.log("Wallet Address:", wallet.address);
console.log("Wallet Seed:", wallet.seed);
// Prepare the transaction ------------------------------------------------
const request = {
"TransactionType": "CheckCreate",
"Account": wallet.address,
"Destination": destination,
"SendMax": amount,
"DestinationTag": 1,
"Fee": "12"
};
// Submit the transaction -------------------------------------------------
console.log("Submitting transaction...");
const tx = await client.submitAndWait(request, { wallet });
// Get the check ID and transaction result --------------------------------
const checkID = tx.result.meta.AffectedNodes.reduce((prevOutput, node) => {
if (node?.CreatedNode && node.CreatedNode?.LedgerEntryType == "Check") {
return node.CreatedNode.LedgerIndex;
} else {
return prevOutput;
}
}, null);
console.log(checkID ? `Check ID: ${checkID}` : "Unable to find the CheckID from parsing the metadata. Look for the LedgerIndex of the 'Check' object within 'meta'.");
console.log(`Transaction: ${JSON.stringify(tx, null, "\t")}`);
// Disconnect -------------------------------------------------------------
await client.disconnect();
} catch (error) {
console.error(`Error: ${error}`)
}
};
main();

View File

@@ -0,0 +1,55 @@
'use strict'
const xrpl = require('xrpl');
const address = "rEYyvXCwv1WJ6a8hW4sBx5afXbJTK97bbR"; // <-- Change this to your account
const main = async () => {
try {
// Connect ----------------------------------------------------------------
const client = new xrpl.Client('wss://s.altnet.rippletest.net:51233');
await client.connect();
let currMarker = null;
let account_objects = [];
// Loop through all account objects until marker is undefined --------------
do {
const payload = {
"command": "account_objects",
"account": address,
"ledger_index": "validated",
"type": "check",
};
if(currMarker !== null) {
payload.marker = currMarker;
};
let { result: { account_objects : checks, marker } } = await client.request(payload);
if (marker === currMarker) {
break;
}
account_objects.push(...checks);
currMarker = marker;
} while (typeof currMarker !== "undefined")
// Print results ----------------------------------------------------------
if (account_objects.length === 0) {
console.log("No checks found.");
} else {
console.log("Checks: \n", JSON.stringify(account_objects, null, "\t"));
};
// Disconnect -------------------------------------------------------------
await client.disconnect();
} catch (error) {
console.log(error);
process.exit(0);
}
}
main();

View File

@@ -4,6 +4,7 @@
"version": "0.0.1",
"license": "MIT",
"dependencies": {
"ripple-lib": "^1.0.0-beta.1"
"ripple-lib": "^1.0.0-beta.1",
"xrpl": "^2.8.0-beta.0"
}
}