Skip to content

Commit

Permalink
Merge e0057d6 into 1cf1ffa
Browse files Browse the repository at this point in the history
  • Loading branch information
hurrytospring committed Feb 14, 2019
2 parents 1cf1ffa + e0057d6 commit 86539ec
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"rpc": "node test/bin/startRPC",
"lint": "eslint ./ --cache",
"lint-all": "eslint ./",
"prerelease-alpha": "npm run build && npm version prerelease",
"prepublish-alpha": "npm run build && npm version prerelease",
"publish-alpha": "npm publish --access-public --tag alpha",
"publish": "npm dist-tag add @vite/vitejs@alpha latest"
},
Expand Down
4 changes: 2 additions & 2 deletions src/Wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ class Account {
}

async callContract({
toAddress, abi, methodName, params, tokenId, amount
toAddress, jsonInterface, params, tokenId, amount
}) {
const _callContractBlock = await this._client.buildinTxBlock.callContract({
accountAddress: this.address,
toAddress, abi, methodName, params, tokenId, amount
toAddress, jsonInterface, params, tokenId, amount
});
return this._client.buildinLedger.sendRawTx(_callContractBlock, this.privateKey);
}
Expand Down
9 changes: 5 additions & 4 deletions src/client/txBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RPCresponse, SBPregBlock, block8, block7, revokeVotingBlock, quotaBlock
import { checkParams, validNodeName } from "utils/tools";
import { formatAccountBlock, validReqAccountBlock } from "utils/builtin";
import { getAccountBlock as _getAccountBlock, getSendTxBlock, getReceiveTxBlock } from 'utils/accountBlock';
import {encodeFunctionCall} from "utils/abi"

import client from '.';

Expand Down Expand Up @@ -339,19 +340,19 @@ export default class tx {
}

async callContract({
accountAddress, toAddress, tokenId, amount, abi, methodName, params, height, prevHash, snapshotHash
accountAddress, toAddress, tokenId, amount, jsonInterface, params=[], height, prevHash, snapshotHash
}: callContractBlock, requestType = 'async') {
let err = checkParams({ toAddress, abi, methodName, tokenId, amount }, ['toAddress', 'abi', 'methodName', 'tokenId', 'amount']);
let err = checkParams({ toAddress, jsonInterface, tokenId, amount }, ['toAddress', 'jsonInterface','tokenId', 'amount']);
if (err) {
return Promise.reject(err);
}

const result:RPCresponse = await this._client.contract.getCallContractData(abi, methodName, params);
// const result:RPCresponse = await this._client.contract.getCallContractData(abi, methodName, params);
return this[`${requestType}AccountBlock`]({
blockType: 2,
accountAddress,
toAddress,
data: result,
data: encodeFunctionCall(jsonInterface,params),
height, prevHash, snapshotHash, tokenId, amount
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/const/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ export const Default_Hash = '000000000000000000000000000000000000000000000000000
export const Quota_Addr = 'vite_000000000000000000000000000000000000000309508ba646';
export const Vote_Addr = 'vite_000000000000000000000000000000000000000270a48cc491';
export const Register_Addr = 'vite_0000000000000000000000000000000000000001c9e9f25417';
export const DexFund_Addr='vite_000000000000000000000000000000000000000617d47459a8';
export const DexTrade_Addr='vite_000000000000000000000000000000000000000768ef0e6238';
5 changes: 2 additions & 3 deletions src/const/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,10 @@ export declare type createContractBlock = {
export declare type callContractBlock = {
accountAddress: Address,
toAddress: Address,
abi: string,
jsonInterface: object,
tokenId: TokenId,
amount: BigInt,
methodName: string,
params?: string,
params?: [],
prevHash?: Hex,
height?: Uint64,
snapshotHash?: Hex
Expand Down
48 changes: 23 additions & 25 deletions src/utils/abi/index.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import { isArray } from 'utils/encoder';
import { isArray } from 'utils/encoder';
import encodeFunction from './encodeFunction';
import { encodeParameter, encodeParameters, decodeParameter, decodeParameters } from './coder/index';
import { encodeParameter as _encodeParameter, encodeParameters as _encodeParameters, decodeParameter as _decodeParameter, decodeParameters as _decodeParameters } from './coder';

export default {
encodeFunctionSignature,
encodeLogSignature(jsonFunction, mehtodName?) {
return encodeFunction(jsonFunction, mehtodName);
},
encodeParameter(type, param) {
return encodeParameter(type, param).result;
},
encodeParameters,
encodeFunctionCall(jsonInterface, params) {
let inputs = jsonInterface.inputs;
let types = [];
inputs.forEach(({ type }) => {
types.push(type);
});
return encodeFunctionSignature(jsonInterface) + encodeParameters(types, params)
},
decodeParameter,
decodeParameters,
decodeLog

export function encodeLogSignature(jsonFunction, mehtodName?) {
return encodeFunction(jsonFunction, mehtodName);
}
export function encodeParameter(type, param) {
return _encodeParameter(type, param).result;
}
export const encodeParameters = _encodeParameters
export const decodeParameter = _decodeParameter
export const decodeParameters = _decodeParameters
export function encodeFunctionCall(jsonInterface, params) {
let inputs = jsonInterface.inputs;
let types = [];
inputs.forEach(({ type }) => {
types.push(type);
});
return encodeFunctionSignature(jsonInterface) + encodeParameters(types, params)
}

function encodeFunctionSignature(jsonFunction, mehtodName?) {

export function encodeFunctionSignature(jsonFunction, mehtodName?) {
let result = encodeFunction(jsonFunction, mehtodName);
return result.slice(0, 8);
}

function decodeLog(inputs, data = '', topics) {
export function decodeLog(inputs, data = '', topics) {
let topicCount = 0;
topics = isArray(topics) ? topics : [topics];

Expand All @@ -52,7 +50,7 @@ function decodeLog(inputs, data = '', topics) {

let returnValues = {};
let notIndexedCount = 0;

indexedParams.forEach(({ indexed, name, result }, i) => {
if (!indexed) {
result = notIndexedParams[notIndexedCount];
Expand Down
2 changes: 1 addition & 1 deletion test/utils/abi.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const assert = require('assert');

import abi from 'utils/abi/index';
import * as abi from 'utils/abi/index';

describe('utils/tools', function () {
it('encodeParameter', function () {
Expand Down

0 comments on commit 86539ec

Please sign in to comment.