How to use xpring-common-js - 10 common examples

To help you get started, we’ve selected a few xpring-common-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultFeeResponse(): Fee {
    const amount = new XRPAmount();
    amount.setDrops("10");

    const fee = new Fee();
    fee.setAmount(amount);

    return fee;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultAccountInfoResponse(): AccountInfo {
    const balance = new XRPAmount();
    balance.setDrops("4000");

    const accountInfo = new AccountInfo();
    accountInfo.setBalance(balance);

    return accountInfo;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultAccountInfoResponse(): AccountInfo {
    const balance = new XRPAmount();
    balance.setDrops("4000");

    const accountInfo = new AccountInfo();
    accountInfo.setBalance(balance);

    return accountInfo;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultFeeResponse(): Fee {
    const amount = new XRPAmount();
    amount.setDrops("10");

    const fee = new Fee();
    fee.setAmount(amount);

    return fee;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultLedgerSequenceResponse(): LedgerSequence {
    const ledgerSequence = new LedgerSequence();
    ledgerSequence.setIndex(12);

    return ledgerSequence;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
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;
  }
github xpring-eng / Xpring-JS / test / fakes / fake-network-client.ts View on Github external
public static defaultTransactionStatusResponse(): TransactionStatus {
    const transactionStatus = new TransactionStatus();
    transactionStatus.setValidated(true);
    transactionStatus.setTransactionStatusCode("tesSUCCESS");

    return transactionStatus;
  }
}
github xpring-eng / Xpring-JS / src / default-xpring-client.ts View on Github external
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());
    });
  }
github xpring-eng / Xpring-JS / src / default-xpring-client.ts View on Github external
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)
                );
github xpring-eng / Xpring-JS / src / default-xpring-client.ts View on Github external
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