Skip to content

Commit

Permalink
some
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelycs committed Mar 5, 2019
1 parent 58f76ed commit 366f2c3
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 28 deletions.
12 changes: 10 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,16 @@ export enum BuiltinTxType {
RevokeVoting,
GetQuota,
WithdrawalOfQuota,
TokenIssuance,
WithdrawalOfToken,
Mintage,
MintageIssue,
MintageBurn,
MintageTransferOwner,
MintageChangeTokenType,
MintageCancelPledge,
DexFundUserDeposit,
DexFundUserWithdraw,
DexFundNewOrder,
DexTradeCancelOrder,
CreateContractReq,
TxReq,
RewardReq,
Expand Down
45 changes: 39 additions & 6 deletions src/const/contract.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { encodeFunctionSignature } from 'utils/abi';

export const Vite_TokenId = 'tti_5649544520544f4b454e6e40';
export const Default_Hash = '0000000000000000000000000000000000000000000000000000000000000000'; // A total of 64 0

Expand All @@ -11,12 +13,6 @@ export const Mintage_Addr = 'vite_00000000000000000000000000000000000000056ad6d2
export const DexFund_Addr = 'vite_000000000000000000000000000000000000000617d47459a8';
export const DexTrade_Addr = 'vite_000000000000000000000000000000000000000768ef0e6238';

// DEX
export const DexFundUserDeposit_Abi = {'type':'function','name':'DexFundUserWithdraw', 'inputs':[{'name':'token','type':'tokenId'},{'name':'amount','type':'uint256'}]};
export const DexFundUserWithdraw_Abi = {'type':'function','name':'DexFundUserWithdraw', 'inputs':[{'name':'token','type':'tokenId'},{'name':'amount','type':'uint256'}]};
export const DexTradeCancelOrder_Abi = {'type':'function','name':'DexTradeCancelOrder', 'inputs':[{'name':'orderId','type':'bytes'}, {'name':'tradeToken','type':'tokenId'}, {'name':',quoteToken','type':'tokenId'}, {'name':'side', 'type':'bool'}]};
export const DexFundNewOrder_Abi = {'type':'function','name':'DexFundNewOrder', 'inputs':[{'name':'orderId','type':'bytes'}, {'name':'tradeToken','type':'tokenId'}, {'name':'quoteToken','type':'tokenId'}, {'name':'side', 'type':'bool'}, {'name':'orderType', 'type':'uint32'}, {'name':'price', 'type':'string'}, {'name':'quantity', 'type':'uint256'}]};

// SBP
export const Register_Abi = {"type":"function","name":"Register", "inputs":[{"name":"gid","type":"gid"},{"name":"name","type":"string"},{"name":"nodeAddr","type":"address"}]};
export const UpdateRegistration_Abi = {"type":"function","name":"UpdateRegistration", "inputs":[{"name":"gid","type":"gid"},{"Name":"name","type":"string"},{"name":"nodeAddr","type":"address"}]};
Expand All @@ -38,3 +34,40 @@ export const Burn_Abi = {"type":"function","name":"Burn","inputs":[]};
export const TransferOwner_Abi = {"type":"function","name":"TransferOwner","inputs":[{"name":"tokenId","type":"tokenId"},{"name":"newOwner","type":"address"}]};
export const ChangeTokenType_Abi = {"type":"function","name":"ChangeTokenType","inputs":[{"name":"tokenId","type":"tokenId"}]};
export const Mint_CancelPledge_Abi = {"type":"function","name":"CancelPledge","inputs":[{"name":"tokenId","type":"tokenId"}]};

// DEX
export const DexFundUserDeposit_Abi = {'type':'function','name':'DexFundUserWithdraw', 'inputs':[{'name':'token','type':'tokenId'},{'name':'amount','type':'uint256'}]};
export const DexFundUserWithdraw_Abi = {'type':'function','name':'DexFundUserWithdraw', 'inputs':[{'name':'token','type':'tokenId'},{'name':'amount','type':'uint256'}]};
export const DexTradeCancelOrder_Abi = {'type':'function','name':'DexTradeCancelOrder', 'inputs':[{'name':'orderId','type':'bytes'}, {'name':'tradeToken','type':'tokenId'}, {'name':',quoteToken','type':'tokenId'}, {'name':'side', 'type':'bool'}]};
export const DexFundNewOrder_Abi = {'type':'function','name':'DexFundNewOrder', 'inputs':[{'name':'orderId','type':'bytes'}, {'name':'tradeToken','type':'tokenId'}, {'name':'quoteToken','type':'tokenId'}, {'name':'side', 'type':'bool'}, {'name':'orderType', 'type':'uint32'}, {'name':'price', 'type':'string'}, {'name':'quantity', 'type':'uint256'}]};


export const contractAddrs = {
Quota: Quota_Addr,
Vote: Vote_Addr,
Register: Register_Addr,
Mintage: Mintage_Addr,
DexFund: DexFund_Addr,
DexTrade: DexTrade_Addr
}

export const abiFuncSignature = {
Register: encodeFunctionSignature(Register_Abi),
UpdateRegistration: encodeFunctionSignature(UpdateRegistration_Abi),
CancelRegister: encodeFunctionSignature(CancelRegister_Abi),
Reward: encodeFunctionSignature(Reward_Abi),
Vote: encodeFunctionSignature(Vote_Abi),
CancelVote: encodeFunctionSignature(CancelVote_Abi),
Pledge: encodeFunctionSignature(Pledge_Abi),
CancelPledge: encodeFunctionSignature(CancelPledge_Abi),
Mint: encodeFunctionSignature(Mint_Abi),
Issue: encodeFunctionSignature(Issue_Abi),
Burn: encodeFunctionSignature(Burn_Abi),
TransferOwner: encodeFunctionSignature(TransferOwner_Abi),
ChangeTokenType: encodeFunctionSignature(ChangeTokenType_Abi),
Mint_CancelPledge: encodeFunctionSignature(Mint_CancelPledge_Abi),
DexFundUserDeposit: encodeFunctionSignature(DexFundUserDeposit_Abi),
DexFundUserWithdraw: encodeFunctionSignature(DexFundUserWithdraw_Abi),
DexFundNewOrder: encodeFunctionSignature(DexFundNewOrder_Abi),
DexTradeCancelOrder: encodeFunctionSignature(DexTradeCancelOrder_Abi)
}
17 changes: 12 additions & 5 deletions src/const/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum BlockType {
SendRefund
}


export enum BuiltinTxType {
SBPreg = 0,
UpdateReg,
Expand All @@ -46,16 +47,22 @@ export enum BuiltinTxType {
RevokeVoting,
GetQuota,
WithdrawalOfQuota,
TokenIssuance,
WithdrawalOfToken,
Mintage,
MintageIssue,
MintageBurn,
MintageTransferOwner,
MintageChangeTokenType,
MintageCancelPledge,
DexFundUserDeposit,
DexFundUserWithdraw,
DexFundNewOrder,
DexTradeCancelOrder,
CreateContractReq,
TxReq,
RewardReq,
TxRes,
TxResFail,
SendRefund
TxResFail
}

export enum LangList {
english = 'english',
japanese = 'japanese',
Expand Down
53 changes: 38 additions & 15 deletions src/utils/accountBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@ import { checkParams, getRawTokenid } from "utils/tools";
import { getAddrFromHexAddr } from 'utils/address/privToAddr';
import { formatAccountBlock, validReqAccountBlock } from "utils/builtin";

import { Default_Hash } from 'const/contract';
import { Default_Hash, contractAddrs, abiFuncSignature } from 'const/contract';
import { paramsMissing, paramsFormat } from "const/error";
import { AccountBlock, BlockType, SignBlock, sendTxBlock, receiveTxBlock, syncFormatBlock } from "const/type";


enum txType {
'f29c6ce2_vite_0000000000000000000000000000000000000001c9e9f25417' = 'SBPreg',
'3b7bdf74_vite_0000000000000000000000000000000000000001c9e9f25417' = 'UpdateReg',
'60862fe2_vite_0000000000000000000000000000000000000001c9e9f25417' = 'RevokeReg',
'ce1f27a7_vite_0000000000000000000000000000000000000001c9e9f25417' = 'RetrieveReward',
'fdc17f25_vite_000000000000000000000000000000000000000270a48cc491' = 'Voting',
'a629c531_vite_000000000000000000000000000000000000000270a48cc491' = 'RevokeVoting',
'8de7dcfd_vite_000000000000000000000000000000000000000309508ba646' = 'GetQuota',
'9ff9c7b6_vite_000000000000000000000000000000000000000309508ba646' = 'WithdrawalOfQuota',
'46d0ce8b_vite_00000000000000000000000000000000000000056ad6d26692' = 'TokenIssuance',
'9b9125f5_vite_00000000000000000000000000000000000000056ad6d26692' = 'WithdrawalOfToken'
};

const txType = enumTxType();

export function getAccountBlock({
blockType, fromBlockHash, accountAddress, message, data, height, prevHash, snapshotHash, toAddress, tokenId, amount, nonce
Expand Down Expand Up @@ -161,3 +148,39 @@ export function signAccountBlock(accountBlock: SignBlock, privKey: string) {

return _accountBlock;
}



function enumTxType () {
let txType = {};

// Register
txType[`${abiFuncSignature.Register}_${contractAddrs.Register}`] = 'SBPreg';
txType[`${abiFuncSignature.UpdateRegistration}_${contractAddrs.Register}`] = 'UpdateReg';
txType[`${abiFuncSignature.CancelRegister}_${contractAddrs.Register}`] = 'RevokeReg';
txType[`${abiFuncSignature.Reward}_${contractAddrs.Register}`] = 'RetrieveReward';

// Vote
txType[`${abiFuncSignature.Vote}_${contractAddrs.Vote}`] = 'Voting';
txType[`${abiFuncSignature.CancelVote}_${contractAddrs.Vote}`] = 'RevokeVoting';

// Quota
txType[`${abiFuncSignature.Pledge}_${contractAddrs.Quota}`] = 'GetQuota';
txType[`${abiFuncSignature.CancelPledge}_${contractAddrs.Quota}`] = 'WithdrawalOfQuota';

// Mintage
txType[`${abiFuncSignature.Mint}_${contractAddrs.Mintage}`] = 'Mintage';
txType[`${abiFuncSignature.Issue}_${contractAddrs.Mintage}`] = 'MintageIssue';
txType[`${abiFuncSignature.Burn}_${contractAddrs.Mintage}`] = 'MintageBurn';
txType[`${abiFuncSignature.TransferOwner}_${contractAddrs.Mintage}`] = 'MintageTransferOwner';
txType[`${abiFuncSignature.ChangeTokenType}_${contractAddrs.Mintage}`] = 'MintageChangeTokenType';
txType[`${abiFuncSignature.Mint_CancelPledge}_${contractAddrs.Mintage}`] = 'MintageCancelPledge';

// Dex
txType[`${abiFuncSignature.DexFundUserDeposit}_${contractAddrs.DexFund}`] = 'DexFundUserDeposit';
txType[`${abiFuncSignature.DexFundUserWithdraw}_${contractAddrs.DexFund}`] = 'DexFundUserWithdraw';
txType[`${abiFuncSignature.DexFundNewOrder}_${contractAddrs.DexFund}`] = 'DexFundNewOrder';
txType[`${abiFuncSignature.DexTradeCancelOrder}_${contractAddrs.DexTrade}`] = 'DexTradeCancelOrder';

return txType;
}
16 changes: 16 additions & 0 deletions test/utils/accountBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ describe('getBuiltinTxType', function () {
data: '',
toAddress: 'vite_0000000000000000000000000000000000000001c9e9f25417'
};
let Mintage = {
blockType: 2,
data: 'J62HLgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACyRFUj9g6iwVfcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPQkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABHNzc3MAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
toAddress: 'vite_00000000000000000000000000000000000000056ad6d26692'
};
let DexFundNewOrder = {
blockType: 2,
data: 'QnapywAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMJpWDkEPPlm83AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVklURSBUT0tFTgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABTl1L8Zdh6mfYIzQeegkraivGtApAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACMTUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
toAddress: 'vite_000000000000000000000000000000000000000617d47459a8'
};

it('RevokeVoting', function() {
assert.equal( getBuiltinTxType(RevokeVoting.toAddress, RevokeVoting.data, RevokeVoting.blockType), 'RevokeVoting' );
Expand Down Expand Up @@ -223,6 +233,12 @@ describe('getBuiltinTxType', function () {
it('TxResFail', function() {
assert.equal( getBuiltinTxType(TxResFail.toAddress, TxResFail.data, TxResFail.blockType), 'TxResFail' );
});
it('Mintage', function() {
assert.equal( getBuiltinTxType(Mintage.toAddress, Mintage.data, Mintage.blockType), 'Mintage');
});
it('DexFundNewOrder', function() {
assert.equal( getBuiltinTxType(DexFundNewOrder.toAddress, DexFundNewOrder.data, DexFundNewOrder.blockType), 'DexFundNewOrder');
});
});

describe('signAccountBlock', function () {
Expand Down

0 comments on commit 366f2c3

Please sign in to comment.