Skip to content

Commit

Permalink
tx: export Transaction class
Browse files Browse the repository at this point in the history
closes #192
  • Loading branch information
notatestuser committed Sep 2, 2019
1 parent 5ced60b commit ec43625
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import * as decoder from "./decoder"
import * as utils from "./utils"
import rpc from "./rpc/client"
import Ledger from "./ledger"
import Transaction from "./tx"

const { BncClient } = client
const amino = { ...encoder, ...decoder }

module.exports = BncClient
module.exports.Transaction = Transaction

module.exports.crypto = crypto
module.exports.amino = amino
module.exports.utils = utils
Expand Down
48 changes: 24 additions & 24 deletions src/token/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @module Token
*/
import Big from 'big.js'
import { txType } from '../tx/'
import { TxTypes } from '../tx/'
import * as crypto from '../crypto/'
import { api } from '../client/'
import { validateSymbol } from '../utils/validateHelper'
Expand Down Expand Up @@ -34,7 +34,7 @@ class TokenManagement {
static instance

/**
* @param {Object} bncClient
* @param {Object} bncClient
*/
constructor(bncClient) {
if (!TokenManagement.instance) {
Expand All @@ -47,11 +47,11 @@ class TokenManagement {

/**
* create a new asset on Binance Chain
* @param {String} - senderAddress
* @param {String} - tokenName
* @param {String} - symbol
* @param {Number} - totalSupply
* @param {Boolean} - mintable
* @param {String} - senderAddress
* @param {String} - tokenName
* @param {String} - symbol
* @param {Number} - totalSupply
* @param {Boolean} - mintable
* @returns {Promise} resolves with response (success or fail)
*/
async issue(senderAddress, tokenName, symbol, totalSupply = 0, mintable = false) {
Expand Down Expand Up @@ -80,7 +80,7 @@ class TokenManagement {
symbol,
total_supply: totalSupply,
mintable,
msgType: txType.IssueMsg
msgType: TxTypes.IssueMsg
}

const signIssueMsg = {
Expand All @@ -97,9 +97,9 @@ class TokenManagement {

/**
* freeze some amount of token
* @param {String} fromAddress
* @param {String} symbol
* @param {String} amount
* @param {String} fromAddress
* @param {String} symbol
* @param {String} amount
* @returns {Promise} resolves with response (success or fail)
*/
async freeze(fromAddress, symbol, amount) {
Expand All @@ -115,7 +115,7 @@ class TokenManagement {
from: crypto.decodeAddress(fromAddress),
symbol,
amount,
msgType: txType.FreezeMsg
msgType: TxTypes.FreezeMsg
}

const freezeSignMsg = {
Expand All @@ -130,9 +130,9 @@ class TokenManagement {

/**
* unfreeze some amount of token
* @param {String} fromAddress
* @param {String} symbol
* @param {String} amount
* @param {String} fromAddress
* @param {String} symbol
* @param {String} amount
* @returns {Promise} resolves with response (success or fail)
*/
async unfreeze(fromAddress, symbol, amount) {
Expand All @@ -147,7 +147,7 @@ class TokenManagement {
from: crypto.decodeAddress(fromAddress),
symbol,
amount,
msgType: txType.UnfreezeMsg
msgType: TxTypes.UnfreezeMsg
}

const unfreezeSignMsg = {
Expand All @@ -162,9 +162,9 @@ class TokenManagement {

/**
* burn some amount of token
* @param {String} fromAddress
* @param {String} symbol
* @param {Number} amount
* @param {String} fromAddress
* @param {String} symbol
* @param {Number} amount
* @returns {Promise} resolves with response (success or fail)
*/
async burn(fromAddress, symbol, amount) {
Expand All @@ -179,7 +179,7 @@ class TokenManagement {
from: crypto.decodeAddress(fromAddress),
symbol,
amount,
msgType: txType.BurnMsg
msgType: TxTypes.BurnMsg
}

const burnSignMsg = {
Expand All @@ -194,9 +194,9 @@ class TokenManagement {

/**
* mint tokens for an existing token
* @param {String} fromAddress
* @param {String} symbol
* @param {Number} amount
* @param {String} fromAddress
* @param {String} symbol
* @param {Number} amount
* @returns {Promise} resolves with response (success or fail)
*/
async mint(fromAddress, symbol, amount) {
Expand All @@ -213,7 +213,7 @@ class TokenManagement {
from: crypto.decodeAddress(fromAddress),
symbol,
amount,
msgType: txType.MintMsg
msgType: TxTypes.MintMsg
}

const mintSignMsg = {
Expand Down
16 changes: 10 additions & 6 deletions src/tx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as crypto from "../crypto/"
import * as encoder from "../encoder/"
import { UVarInt } from "../encoder/varint"

export const txType = {
export const TxTypes = {
MsgSend: "MsgSend",
NewOrderMsg: "NewOrderMsg",
CancelOrderMsg: "CancelOrderMsg",
Expand All @@ -20,7 +20,7 @@ export const txType = {
MsgVote: "MsgVote"
}

export const typePrefix = {
export const TypePrefixes = {
MsgSend: "2A2C87FA",
NewOrderMsg: "CE6DC043",
CancelOrderMsg: "166E681B",
Expand Down Expand Up @@ -62,7 +62,7 @@ export const typePrefix = {
*/
class Transaction {
constructor(data) {
if (!txType[data.type]) {
if (!TxTypes[data.type]) {
throw new TypeError(`does not support transaction type: ${data.type}`)
}

Expand Down Expand Up @@ -159,7 +159,7 @@ class Transaction {
memo: this.memo,
source: this.source, // sdk value is 0, web wallet value is 1
data: "",
msgType: txType.StdTx
msgType: TxTypes.StdTx
}

const bytes = encoder.marshalBinary(stdTx)
Expand Down Expand Up @@ -188,7 +188,11 @@ class Transaction {
}
}

Transaction.txType = txType
Transaction.typePrefix = typePrefix
Transaction.TxTypes = TxTypes
Transaction.TypePrefixes = TypePrefixes

// DEPRECATED: Retained for backward compatibility
Transaction.txType = TxTypes
Transaction.typePrefix = TypePrefixes

export default Transaction

0 comments on commit ec43625

Please sign in to comment.