1.5.0 • Published 3 years ago

@cosmic-plus/tx-result v1.5.0

Weekly downloads
7
License
MIT
Repository
github
Last release
3 years ago

tx-result / ReadmeContributingChangelog

Readme

Licence Dependencies Vulnerabilities Bundle Downloads

Turns Stellar Horizon responses into meaningful descriptions.

(Weekly updates: Reddit, Twitter, Keybase, Telegram)

Introduction

After posting a transaction to the network, most software needs to display comprehensive feedback to the user. This is especially true when an error happens.

This library produces human-readable descriptions for any possible code Stellar Core returns:

const response = await server.submitTransaction(transaction)
const result = new TxResult(response)

Result for successful transactions:

{
 validated: true,
 title: "The transaction has been validated",
 hash: "d89c...007e",
 ledger: 370369,
 offerResults: undefined,
 link: "https://horizon-testnet.stellar.org/transactions/d89c...007e"
}

Note: offerResults is as described in StellarSdk [server.submitTransaction()](https://stellar.github.io/js-stellar-sdk/Server.html#submitTransaction) documentation.

Result for failed transactions:

{
 validated: false,
 title: "The transaction has been rejected",
 errors: [
   "Operation 1: The destination account doesn't exist.",
   "Operation 3: The source does not have enough funds."
 ]
}

Installation

NPM/Yarn

  • NPM: npm install @cosmic-plus/tx-result
  • Yarn: yarn add @cosmic-plus/tx-result

In your script: const txResult = require("@cosmic-plus/tx-result")

Bower

bower install cosmic-plus-tx-result

In your HTML page:

<script src="./bower_components/cosmic-plus-tx-result/tx-result.js"></script>

CDN

In your HTML page:

<script src="https://cdn.cosmic.plus/tx-result@1.x"></script>

Note: For production release it is advised to serve your copy of the library.

Usage

Functions

new TxResult(txResponse)

The TxResult constructor.

ParamTypeDescription
txResponseObjectA response returned by StellarSdk server.submitTransaction().

await TxResult.fromPromise(promise) ⇒ TxResult

Returns the TxResult for an unresolved StellarSdk server.submitTransaction() Promise.

ParamTypeDescription
promisePromiseAn unresolved Horizon response.

TxResult.describeTxCode(code) ⇒ String

Returns a comprehensive description for transaction return code.

See: Transaction possible errors

ParamTypeDescription
codeStringA Stellar transaction return code.

TxResult.describeOpCode(code) ⇒ String

Returns a comprehensive description for operation return code.

See: Operations possible errors

ParamTypeDescription
codeStringA Stellar operation return code.

await TxResult.forCosmicLink(cosmicLink) ⇒ TxResult

Submits cosmicLink using cosmicLink.send() then returns its TxResult. The advantage of using this function is that it generates reports for callbacks and StellarGuard submission as well.

ParamTypeDescription
cosmicLinkCosmicLinkA .lock()ed cosmicLink

Links

Organization: Cosmic.plus | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase