@laverna_ritchie5/xwallet
v0.9.101
Published
xwallet
Downloads
602
Readme
wallet-lib
1、概览
1.1 概念说明
1.2 错误码定义
1.3 集成说明
npm install @laverna_ritchie5/xwallet
import * as sdk from "../src/index"
//配置
export const DefaultWalletConfig: WalletConfig = {
apiOptions: {
url: "http://47.242.165.128:8157",
cnhtApiHost: "http://localhost:9020/1/api/v1",
version: "v1.0.0",
profile: "dev",
getUserInfo: () => { im_id: 0 },
getToken: () => "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBfa2V5IjoiIiwiZGV2aWNlX2lkIjoiIiwiZXhwIjoxNjM2OTU3ODMwLCJpYXQiOjE2MzYwOTM4MzAsImltX2lkIjoxMDExOSwiaXNzIjoiMSIsInBsYXRmb3JtIjoiYW5kcm9pZCIsInNlc3Npb24iOjE2MzYwOTM4MzAxNzd9.x052PhX9F8Cb2C7v0fy82b5xNe_VdxH4RESSKxhzA_A"
},
enableAxiosLogger: false,//是否开启Axios日志
environment: "development",//development staging production
seqUrl: "",//测试日志地址
enrichFunction: () => { return { imId: 0 } },//日志扩展参数
getLanguage: () => { return "en" },//语言
getCurrency: async () => {//返回币种
return {
name: '人民币',
symbol: 'CN¥',
symbolNative: '¥',
decimalDigits: 2,
rounding: 0,
code: 'CNY',
namePlural: 'Chinese yuan',
}
},
getStorage: async (key) => { console.log("getStorage", key); return undefined },//查询存储
setStorage: async (key, data) => { console.log("setStorage", key, data) },//设置存储
}
export const DefaultWalletStorage: WalletStorage = {
db: new Map<string, Wallet>(),
add: async (wallet) => { DefaultWalletStorage.db!.set(wallet.id, wallet); return wallet },
update: async (walletId, params, desc) => {
let wallet = DefaultWalletStorage.db!.get(walletId)
DefaultWalletStorage.db!.set(walletId, { ...wallet, ...params } as Wallet);
console.log(desc);
},
remove: async (walletId: string) => { DefaultWalletStorage.db!.delete(walletId) },
removeAll: async () => { DefaultWalletStorage.db!.clear() },
getList: async () => { return Array.from(DefaultWalletStorage.db!.values()) },
get: async (walletId: string) => { return DefaultWalletStorage.db!.get(walletId)! },
};
export const DefaulTagStorage: TagStorage = {
db: new Map<string, Tag>(),
add: async (tag) => { DefaulTagStorage.db!.set(tag.id, tag); return tag },
update: async (tagId, params, desc) => {
let tag = DefaulTagStorage.db!.get(tagId)
DefaulTagStorage.db!.set(tagId, { ...tag, ...params } as Tag);
console.log(desc);
},
remove: async (tagId: string) => { DefaulTagStorage.db!.delete(tagId) },
removeAll: async () => { DefaulTagStorage.db!.clear() },
getList: async () => { return Array.from(DefaulTagStorage.db!.values()) },
get: async (tagId: string) => { return DefaulTagStorage.db!.get(tagId)! },
};
export const DefaultPendingTxStorage: PendingTxStorage = {
db: new Map<string, PengdingTx>(),
add: async (pendingTx) => { DefaultPendingTxStorage.db!.set(pendingTx.transactionHash, pendingTx) },
remove: async (txHash: string) => { DefaultPendingTxStorage.db!.delete(txHash) },
removeAll: async () => { DefaultPendingTxStorage.db!.clear() },
getList: async () => { return Array.from(DefaultPendingTxStorage.db!.values()) },
get: async (txHash: string) => { return DefaultPendingTxStorage.db!.get(txHash)! },
};
export const DefaultEventBus: Map<string, Function> = new Map<string, Function>([
["assetCurrencyValueChange", (wallet, eto) => { console.log("assetCurrencyValueChange", wallet.id, eto) }],
["txStatusChange", (tx, eto) => { console.log("txStatusChange", tx.transactionHash, eto) }]
]);
/**
* 初始化SDK
* @param config 基本配置
* @param storage 钱包存储
* @param txStorage 待刷新交易存储
* @param bus 事件
*/
export declare function initialize(config: WalletConfig, storage: WalletStorage, gStorage: TagStorage, txStorage: PendingTxStorage, bus: Map<string, Function>): void;
/**
* 初始化Token列表
*/
export declare function initTokenList(): Promise<void>;
2、API Reference
助记词
/**
* 生成助记词
*
* @param {string} size The new phrase size.
* @returns {string} The generated phrase based on the size.
*/
export declare const generatePhrase: (size?: number) => string
/**
* 检查助记词
*
* @param {string} phrase
* @returns {boolean} `true` or `false`
*/
export declare const validatePhrase: (phrase: string) => boolean
/**
* Get the seed from the given phrase.
*
* @param {string} phrase
* @returns {Buffer} The seed from the given phrase.
*
* @throws {"Invalid BIP39 phrase"} Thrown if phrase is an invalid one.
*/
export declare const getSeed: (phrase: string) => Buffer
/**
* Get the Keystore interface from the given phrase and password.
*
* @param {string} phrase
* @param {string} password
* @returns {Keystore} The keystore interface generated from the given phrase and password.
*
* @throws {"Invalid BIP39 phrase"} Thrown if phrase is an invalid one.
*/
export declare const encryptToKeyStore: (phrase: string, password: string) => Promise<Keystore>
/**
* Get the phrase from the keystore
*
* @param {Keystore} keystore
* @param {string} password
* @returns {Keystore} The phrase from the keystore.
*
* @throws {"Invalid password"} Thrown if password is an incorrect one.
*/
export declare const decryptFromKeystore: (keystore: Keystore, password: string) => Promise<string>
WalletService
/**
* 获取tag列表
* @returns
*/
export declare function getTagList(): Promise<Tag[]>
/**
* 获取tag
* @returns
*/
export declare function getTag(id: string): Promise<Tag>
/**
* 获取Main tag
* @returns
*/
export declare function getMainTag(): Promise<Tag>
/**
* 获取钱包列表
* @param params
* @returns
*/
export declare function getWalletList(params?: QueryWalletsDto): Promise<Wallet[]>
/**
* 创建钱包
* @param coins 币种
* @param belongMain 属于主钱包
* @param name 名称
* @param originalPassword 密码
* @param originalMnemonic 助记词
*/
export declare function createWallets(params: CreateWalletDto): Promise<Tag>
/**
* 添加币种
* @param coins 币种
* @param belongMain 属于主钱包
* @param originalPassword 密码
* @param originalMnemonic 助记词
*/
export declare function addCoins(tagId: string, coins: CoinDto[], originalPassword?: string): Promise<void>
/**
* 重新初始化CNHT钱包
* @param originalPassword 原始密码
* @param originalMnemonic 助记词,可选
* @param checkedPassword 是否检查密码, 可选
* @returns
*/
export declare function checkAndInitCnhtWallet(originalPassword: string): Promise<Wallet>
/**
* 添加币种,是否需要密码
* @param coins 币种
*/
export declare function requirePwdWhenAddCoins(tagId: string, coins: CoinDto[]): Promise<boolean>
/**
* 移除主币种
* @param token 代币
*/
export declare function removeToken(tagId: string, chainName: string, contract?: string): Promise<void>
/**
* 移除某个分组
* @param id 钱包地址
* @returns
*/
export declare function exitTag(tagId: string): Promise<void>
/**
* 修改分组的名称
* @param id 钱包地址
* @returns
*/
export declare function setTagName(tagId: string, name: string): Promise<void>
/**
* 获取钱包
* @returns
*/
export declare function getWallet(id: string): Promise<Wallet>
/**
* 通过地址获取钱包
* @returns
*/
export declare function getWalletByAddress(address: string): Promise<Wallet>
/**
* 根据address和网络返回钱包
* @param address
* @param networkName
* @returns
*/
export declare function findWallet(address: string, networkName: string): Promise<Wallet | undefined>
/**
* 获取用户所有主币和Token(收款码页面使用)
*/
export declare function getUserAllTokens(): Promise<Token[]>
/**
* 获取用户拥有的币种(转账页面选择币种使用)
*/
export declare function getUserCoins(): Promise<CoinDto[]>
/**
* 获取分组的助记词
* @param password
* @returns
*/
export declare function getTagMnemonic(tagId: string, password: string): Promise<string>
/**
* 检查tag的密码
* @param tagId
* @param password
* @returns
*/
export declare function checkTagPassword(tagId: string, password: string): Promise<boolean>
/**
* 主钱包是否有密码
* @returns
*/
export declare function hasMainPassword(): Promise<boolean>
/**
* 检查主钱包密码
* @returns
*/
export declare function checkMainPassword(password: string): Promise<boolean>
/**
* 修改主密码
* @param oldPassword
* @param newPassword
*/
export declare function changeMainPassword(oldPassword: string, newPassword: string): Promise<void>
/**
* 重置主密码
* @param recoverToken
* @param newPassword
*/
export declare function resetMainPassword(recoverToken: string, newPassword: string): Promise<void>
/**
* 获取创建钱包时的Tag
* @param belongMain
* @returns
*/
export declare function getTagNextSort(belongMain: boolean): Promise<number>
/**
* 初始化visualCnht钱包
* @returns
*/
export declare function initEmptyCnhtWallet(): Promise<Wallet>
/**
* 获取Cnht钱包
* @param params
*/
export declare function getCnhtWallet(): Promise<Wallet>
/**
* 初始化cnht钱包配置
*/
export declare function initCnhtSetting(): Promise<void>
/**
* 获取cnht钱包配置
* @returns
*/
export declare function getCnhtSetting(): Promise<GetCnhtSettingRsp>
/**
* cnht交易签名-转账 发红包 群付款
* @param password
* @param data
*/
export declare function addEccSignToCnhtTransaction(password: string, data: any): Promise<any>
/**
* 是否初始化了cnht钱包 是否有公钥、地址
* 如果返回false,并且用户之前设置过交易密码,则需要校验交易密码,并重新更新钱包公钥、地址
* @param params
*/
export declare function hasInitCnhtWallet(): Promise<boolean>
/**
* 刷新CNHT钱包余额
* @param params
*/
export declare function refreshCnhtWalletBalance(): Promise<void>
/**
* 查询交易回执
* @returns
*/
export declare function queryTxReceipt(params: QueryTxReceiptDto): Promise<UpdateTxDto>
Wallet Methods
export declare class Tag {
id: string;
name: string;
mnemonic: string;
password: string;
passwordHint: string;
belongMain: boolean;
sort: number;
createdAt: Date;
updatedAt?: Date;
tokens: any[];
constructor({ id, mnemonic, name, belongMain, originalMnemonic, originalPassword, passwordHint, password, sort, createdAt, updatedAt }: Partial<Tag> & {
originalMnemonic?: string;
originalPassword?: string;
});
export declare type Account = {
address: string;
privateKey: string;
publicKey?: string;
networkName: string;
};
export declare class Wallet {
id: string;
address: string;
chainName: string;
belongMain: boolean;
tagId: string;
currentNetworkName: string;
tokens: Token[];
accounts: Account[];
createdAt: Date;
updatedAt?: Date;
provider: IChainProvider;
disable: boolean;
tag: Tag;
constructor({ id, chainName, tagId, tokens, accounts, createdAt, updatedAt, currentNetworkName, disable, originalMnemonic, originalPassword, tag, }: Partial<Wallet> & {
originalMnemonic?: string;
originalPassword?: string;
});
getCurrentAccount(): Account;
/**
* 获取私钥
* @param originalPassword
*/
getPrivateKey(originalPassword: string): string;
/**
* 获取单个Token余额
* @param contract 合约地址,不传查询主币余额
* @returns
*/
getTokenBalance(contract?: string): Promise<AssetBalanceChangeEto>;
/**
* 刷新账户所有Token余额
*/
refreshAllBalance(): Promise<void>;
/**
* 刷新单个Token余额
* @param token
* @param price
*/
private refreshTokenBalance;
/**
* 刷新单个Token余额
* @param contract
*/
refreshContractBalance(contract?: string): Promise<void>;
/**
* 估算gas费用
* @param transaction
*/
getFee(tx: SendTxDto): Promise<FeeDto>;
/**
* 发送交易
* @param transaction
*/
sendTransaction(tx: SendTxDto, password: string): Promise<TxDetail>;
/**
* 获取代币列表
* @returns
*/
getTokens(): Token[];
/**
* 是否已经存在代币
* @param contract 代币合约地址
*/
private hasToken;
/**
* 添加代币
* @param tokens
*/
addTokens(tokens: CoinDto[]): Promise<void>;
/**
* 获取token
* @param contract 代币合约地址
*/
getToken(contract?: string): Token | undefined;
/**
* cnht钱包更新tagId
* @param tagId
*/
setTagId(tagId: string): Promise<void>;
/**
* 修改代币别名
* @param contract 代币合约地址
*/
setTokenName(contract: string | undefined, name: string): Promise<void>;
/**
* 移除代币
* @param contract 代币合约地址
*/
removeToken(contract: string): Promise<void>;
/**
* 修改钱包密码
* @param oldOriginalPassword 旧密码
* @param originalPassword 新密码
*/
updatePassword(oldOriginalPassword: string, originalPassword: string): Promise<void>;
formatTxParams(tx: SendTxDto): TxParams;
/**
* 检查密码是否正确
* @param password
* @returns
* @todo 增加group,来实现检查密码
*/
checkPassword(password: string): void;
private updateToStorage;
private checkAndInitMainToken;
/**
* 禁用主钱包
*/
disableWallet(): Promise<void>;
summary(): any;
}
QrcodeService
export interface QrcodeAddress {
amount?: number | string
chainName: string
id: string
type?: string
contract?: string
}
/**
* 解析二维码
* @param qrcode
*/
export declare function parseQrcode(qrcode: string): QrcodeAddress
/**
* 判断是否是二维码地址
* @param address
*/
export declare function isQrcodeAddress(id: string): boolean
/**
* 获取二维码
* @param options
*/
export declare function generateQrcode(chainName: string, id: string, options?: QrcodeOptions): string
ChainService
/**
* 获取所有支持的公链代币
* @deprecated
* @returns
*/
export declare function getSupportChains(): ChainSummary[]
/**
* 获取所有主币和代币
* @returns
*/
export declare function getSupportCoins(): Promise<CoinDto[]>
/**
* 获取某个公链的token列表,暂时只支持以太坊
* @param chainName
* @param networkName
* @returns
*/
export declare function getTokenList(chainName: string, networkName: string): Promise<TokenInfo[]>
/**
* 获取某个代币
* @param chainName
* @param contract
* @param networkName
*/
export declare function getToken(chainName: string, contract?: string, networkName?: string): Promise<CoinDto | undefined>
刷新交易
export declare function startTxRefresher(): void
export declare function stopTxRefresher(): void
/**
* 添加pending的交易
* @param tx
*/
export declare function pushPengdingTx(tx: TxDetail): void
export declare function clearPengdingTx(): void
闪兑
export declare class FlashSwap {
context: BaseSwapContext
wallet: Wallet
amount: string
fromToken: CoinDto
toToken: CoinDto
settings: any
constructor()
/**
* 获取当前trade
* @returns
*/
trade(): import('./model').Trade | undefined
private getAllCoins
/**
* 获取可以兑换的币
* @param symbol
* @returns
*/
getSwapCoins(symbol?: string): Promise<CoinDto[]>
/**
* 设置钱包
* @param wallet
*/
setWallet(wallet: Wallet): Promise<void>
/**
* 设置交易对
* @param from
* @param to
*/
setPairs(from: CoinDto, to: CoinDto): Promise<void>
/**
* 设置兑出金额
* @param amount
*/
setAmout(amount: string): Promise<void>
/**
* 修改settings
* @param wallet
*/
changeSetting(settings: any): Promise<void>
private checkCanPreview
/**
* 是否可以预览
*/
canPreview(): boolean
/**
* 预览
*/
preview(): Promise<void>
approve(password: string): Promise<string>
/**
* 兑换
*/
swap(password: string): Promise<void>
}
Event
export interface AssetBalanceChangeEto {
symbol: string
balance: number | string
contract?: string
networkName: string
}
export interface AssetCurrencyValueChangeEto extends AssetBalanceChangeEto {
currencyValue: number
currency: string
}
export declare enum WalletEventType {
AssetBalanceChange = 'assetBalanceChange',
AssetCurrencyValueChange = 'assetCurrencyValueChange',
TxStatusChange = 'txStatusChange',
NewNotice = 'newNotice',
}
export interface TxStatusChangeEto extends UpdateTxDto {}
Utils
export declare function md5(text: string): string
export declare function sha512(text: string): string
export declare function sha256(text: string): string
export declare function encrypt(text: string, key: string): string
export declare function decrypt(text: string, key: string): string
/**
* 使用私钥生成签名
* @param privateKey
* @param signStr
* @returns
*/
export declare function createEccSignature(privateKey: string, signStr: string): string
/**
* 请求实体进行签名
* @param privateKey
* @param data
* @returns
*/
export declare function addEccSign(privateKey: string, data: any): any
export declare function stringToByte(str: any): number[]
/**
* base单位转为asset单位
* @param baseValue
* @param decimals
* @example sdk.parseToAsset('1000000000000000000', 18)
* @returns
*/
export declare function parseToAsset(baseValue: string | number, decimals: number): string
/**
* asset单位转为base单位
* @param assetValue
* @param decimals
* @example sdk.parseToBase('1', 18)
* @returns
*/
export declare function parseToBase(assetValue: string | number, decimals: number): string
/**
* base单位转为asset单位
* @param baseValue
* @param decimals
* @example sdk.parseToAsset('1000000000000000000', 18)
* @returns
*/
export declare function parseToAssetNumber(baseValue: string | number, decimals: number): number
export declare function getTimestamp(): number
/**
* 格式化手续费
* @param chainName 链名
* @param baseFee base手续费
* @returns asset手续费
*/
export declare function parseBaseFee(baseFee: string, chainName: string): any
/**
* 获取设置的币种Code
* @returns
*/
export declare function getCurrencyCode(): string
/**
* 获取设置的币种符号
* @returns
*/
export declare function getCurrencySymbol(): string
/**
* 获取价格
* @param symbols
* @param target
*/
export declare function getPrices(symbols: string[], target?: string): Promise<Map<string, number>>
/**
* 根据chain名称获取公链信息
* @param chainName
* @returns
*/
export declare function getChain(chainName: string): Chain
/**
* 获取个链下的默认网络名称
* @param chainName
*/
export declare function getChainNetwork(chainName: string): string
/**
* 获取某个公链支持的网络列表
* @param chainName
* @returns
*/
export declare function getChainNetworks(chainName: string): ChainNetwork[]
/**
* 获取链的某个网络
* @param chainName
* @param networkName
*/
export declare function getNetwork(chainName: string, networkName?: string): ChainNetwork
/**
* 获取某个公链的平台代币
* @param chainName
*/
export declare function getMainToken(chainName: string): CoinDto
export declare function getWallets(params?: any): Promise<Wallet[]>
Api Service
Example
import * as sdk from '../src/index'
let api = await sdk.rpc()
let response = await api.transaction.commitTransaction({})
Model
export interface Chain {
icon: string //图标
name: string //名称
symbol: string //币种标识
decimals: number //小数位数
derivedPath?: string
curve?: string
segWit?: string
chainName: string //链名称,用来关联服务唯一键
chainType: string //链类型
networks: ChainNetwork[]
sort: number
}
export interface ChainSummary {
icon?: string //图标
name: string //名称
symbol: string //币种标识
decimals: number //小数位数
chainName?: string //链名称,用来关联服务唯一键
contract?: string
}
// 兼容metamask。每个网络都可以有一个账户
export interface ChainNetwork {
chainId: number //链 ID
networkId: number //网络ID
network: string //网络名称
symbol: string // 符号(选填)/Currency Symbol
networkURL: string //RPC URL/Network URL
explorer?: string //区块浏览器 URL(选填)
tokens?: TokenInfo[] //代币列表
}
export interface CoinDto {
icon?: string //图标
name: string //名称
chainName: string //链名称
symbol: string //符号
decimals: number
contract?: string //合约地址
networkName: string //所属网络
sort: number
}
export type Account = {
address: string
privateKey: string
publicKey?: string
networkName: string
}
export class Wallet {
id: string = '' //id 使用钱包主网地址
address: string = '' //钱包地址
name: string //别名
chainName: string //链名称 bitcoin/ethereum/...
icon: string
symbol: string //符号 ETH/BTC/...
decimals: number //小数位数
balance: number | string
currencyValue: number //法币余额
originalMnemonic?: string //原始助记词
mnemonic: string //加密后的助记词
originalPassword?: string //原始密码:创建钱包时候需要
password: string
passwordHint: string
hasPassword: boolean
belongMain: boolean
rootDerivationPaths: object
currentNetworkName: string //当前网络
tokens: Token[] = [] //代币列表
accounts: Account[] = []
createdAt: Date
updatedAt?: Date
provider: IChainProvider
disable: boolean
}
export class Token {
walletAddress: string //钱包地址
icon: string //图标
name: string //名称
networkName: string //所属网络
contract?: string //合约地址
symbol: string //符号
decimals: number
chainName: string //链名称
balance: number | string //余额
currencyValue: number //法币余额
sort: number
}
export interface QueryWalletsDto {
chainName?: string
belongMain?: boolean
}
export interface CreateOtherWalletDto {
passwordHint: string | undefined
password: string
chainName: string
name: string
mnemonic?: string
}
export interface SetPasswordToCnhtWalletDto {
passwordHint: string | undefined
password: string
}
export interface querySwapFormInfo {
fromTokenContractAddress: string
networkName: string //当前网络??
}
export interface GetSwapFeeDto {
fromTokenContractAddress: string
toTokenContractAddress: string
ethereumAddress: string //以太坊钱包地址
networkName: string //所属网络???
amount: number
}
export interface SendSwapDto {
fromContract?: string //空代表eth
toContract?: string //空代表eth 和fromContract 不能同时为空
ethereumAddress: string //以太坊钱包地址
networkName: string //所属网络???
amount: string
slippage?: number //default: `0.005` which is 0.5%
deadlineMinutes?: number // if not supplied it will use 20 a deadline minutes
disableMultihops?: boolean // if not supplied it will try to use multihops, if this is true it will require swaps to direct pairs
}
/**
* 交易数据
*/
export interface SendTxDto {
symbol: string
contract?: string //token转账需要传入
to: string // 收款地址
value: number //转账金额
decimals: number
gasPrice?: number //单位Wei,以太坊转账必传
gasLimit?: number //以太坊转账必传
note?: string //交易备注
feeRate?: number //比特币转账必传
}
export type FeeDto = {
fee: number
gasPrice?: number //eth 单位Wei
gasLimit?: number //eth
feeRate?: number //btc,BCH
amount?: number
}
// UNAPPROVED: 'unapproved',
// APPROVED: 'approved',
// REJECTED: 'rejected',
// SIGNED: 'signed',
// SUBMITTED: 'submitted',
// FAILED: 'failed',
// DROPPED: 'dropped',
// CONFIRMED: 'confirmed',
export enum TransactionStatus {
PENDING = 0,
SUCCESS = 1,
FAIL = 2,
}
export enum TransactionType {
TRANSFER = 1,
SWAP = 2,
ENTRUST = 3,
}
/**
* 交易详情
*/
export interface TxDetail {
transactionHash: string //交易hash id全局唯一
from: string //转出地址
symbol: string
contract?: string //token转账需要传入
toContract?: string //UniSwap类型的交易才有该字段
to: string // 收款地址
value: number | string //转账金额
decimals: number
gasPrice?: number | string
gasLimit?: number | string
note?: string //交易备注
nonce: number
chainId: number //交易链编号
chainName: string //交易链名称
network: string //交易网络
confirmations: number //确认数
status: TransactionStatus | number //交易状态
timestamp: number
type: TransactionType
transactionFee: string //交易手续费,可能和原始链币种不同
toDecimals?: number
toSymbol?: string
toName?: string
fromValue?: number
toValue?: string | number
signature?: string
failed_reason?: string
}
export interface UpdateTxDto {
transactionHash: string
status: TransactionStatus // PENDING = 0, SUCCESS = 1, FAIL = 2
desc?: string
}
export interface UpdateBitcoinTxDto extends UpdateTxDto {
blockHash: string
// blockNumber: number
confirmations: number
timestamp: number
transactionFee: string
}
export interface UpdateBitcoinCashTxDto extends UpdateTxDto {
blockHash: string
blockNumber: number
confirmations: number
timestamp: number
transactionFee: string
}
export interface UpdateEthereumTxDto extends UpdateTxDto {
//以下字段从交易回执中取
blockHash: string
blockNumber: number
cumulativeGasUsed: number
effectiveGasPrice: number
gasPrice: number
gasUsed: number
transactionIndex: number
confirmations: number
//以下字段从交易详情中取
// confirmations: number,
timestamp: number
transactionFee: string | number
toValue?: string
}
export interface QueryTxReceiptDto {
chainName: string
transactionHash: string
networkName: string
fromContract?: string //当交易类型是swap的时候,需要传交易里的from
toContract?: string //当交易类型是swap的时候,需要传交易里的toContract
type: number // TRANSFER = 1, SWAP = 2, ENTRUST = 3
}
export interface PengdingTx extends TxDetail {}
/**
* 虚拟币交易类型
*/
export enum TransactionDirection {
TRANSFER = 1,
TRANSFER_IN = 10, // 转入
TRANSFER_OUT = 11, // 转出
SWAP = 2, // 兑换
SWAP_IN = 20, // 兑换-买入
SWAP_OUT = 21, // 兑换-卖出
ENTRUST = 3, // 委托
ENTRUST_IN = 30, // 委托买入
ENTRUST_OUT = 31, // 委托卖出
FEE = 5, // 手续费
COIN = 6, // 兑换- 币币兑换
PUBLISH_IN = 9, // 买卖交易 - 进账
PUBLISH_OUT = 10, // 买卖交易 - 出账
}
export interface Notice {
chainName: string //交易链名称
network: string //交易网络
transactionHash: string
from: string //转出地址
symbol: string
to: string // 收款地址
value: number | string //转账金额
status: TransactionStatus
direction: TransactionDirection
}
export interface Trade {
expectedConvertQuote: string
minAmountConvertQuote: string | null
tradeExpires: number
routeText: string
params?: any
destroy?: Function
approvalTransaction?: any
transaction?: any
}