Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static defaultFeeResponse(): Fee {
const amount = new XRPAmount();
amount.setDrops("10");
const fee = new Fee();
fee.setAmount(amount);
return fee;
}
public static defaultAccountInfoResponse(): AccountInfo {
const balance = new XRPAmount();
balance.setDrops("4000");
const accountInfo = new AccountInfo();
accountInfo.setBalance(balance);
return accountInfo;
}
public static defaultAccountInfoResponse(): AccountInfo {
const balance = new XRPAmount();
balance.setDrops("4000");
const accountInfo = new AccountInfo();
accountInfo.setBalance(balance);
return accountInfo;
}
public static defaultFeeResponse(): Fee {
const amount = new XRPAmount();
amount.setDrops("10");
const fee = new Fee();
fee.setAmount(amount);
return fee;
}
public static defaultLedgerSequenceResponse(): LedgerSequence {
const ledgerSequence = new LedgerSequence();
ledgerSequence.setIndex(12);
return ledgerSequence;
}
public static defaultSubmitSignedTransactionResponse(): SubmitSignedTransactionResponse {
const submitSignedTransactionResponse = new SubmitSignedTransactionResponse();
submitSignedTransactionResponse.setEngineResult("tesSUCCESS");
submitSignedTransactionResponse.setEngineResultCode(0);
submitSignedTransactionResponse.setEngineResultMessage(
"The transaction was applied. Only final in a validated ledger."
);
submitSignedTransactionResponse.setTransactionBlob("DEADBEEF");
return submitSignedTransactionResponse;
}
public static defaultTransactionStatusResponse(): TransactionStatus {
const transactionStatus = new TransactionStatus();
transactionStatus.setValidated(true);
transactionStatus.setTransactionStatusCode("tesSUCCESS");
return transactionStatus;
}
}
public async getBalance(address: string): Promise {
if (!Utils.isValidXAddress(address)) {
return Promise.reject(
new Error(XpringClientErrorMessages.xAddressRequired)
);
}
return this.getAccountInfo(address).then(async accountInfo => {
const balance = accountInfo.getBalance();
if (balance === undefined) {
return Promise.reject(
new Error(XpringClientErrorMessages.malformedResponse)
);
}
return BigInt(balance.getDrops());
});
}
public async send(
amount: BigInt | number | string,
destination: string,
sender: Wallet
): Promise {
if (!Utils.isValidXAddress(destination)) {
return Promise.reject(
new Error(XpringClientErrorMessages.xAddressRequired)
);
}
const normalizedAmount = this.toBigInt(amount);
return this.getFee().then(async fee => {
return this.getAccountInfo(sender.getAddress()).then(
async accountInfo => {
return this.getLastValidatedLedgerSequence().then(
async ledgerSequence => {
if (accountInfo.getSequence() === undefined) {
return Promise.reject(
new Error(XpringClientErrorMessages.malformedResponse)
);
payment.setXrpAmount(xrpAmount);
payment.setDestination(destination);
const transaction = new Transaction();
transaction.setAccount(sender.getAddress());
transaction.setFee(fee);
transaction.setSequence(accountInfo.getSequence());
transaction.setPayment(payment);
transaction.setLastLedgerSequence(
ledgerSequence + ledgerSequenceMargin
);
transaction.setSigningPublicKeyHex(sender.getPublicKey());
var signedTransaction;
try {
signedTransaction = Signer.signTransaction(transaction, sender);
} catch (signingError) {
const signingErrorMessage =
XpringClientErrorMessages.signingFailure +
". " +
signingError.message;
return Promise.reject(new Error(signingErrorMessage));
}
if (signedTransaction == undefined) {
return Promise.reject(
new Error(XpringClientErrorMessages.signingFailure)
);
}
const submitSignedTransactionRequest = new SubmitSignedTransactionRequest();
submitSignedTransactionRequest.setSignedTransaction(
signedTransaction