Skip to content

Commit

Permalink
Merge branch 'master' into dev/1.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelycs committed Mar 1, 2019
2 parents 5f73471 + 446674d commit 1f0c733
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 31 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "@vite/vitejs",
"version": "1.1.5-10",
"version": "1.1.5-11",
"description": "",
"main": "dist/vitejs/index.node.js",
"browser": "dist/vitejs/index.web.js",
"typings": "index.d.ts",
"scripts": {
"build:browser": "build_target=web webpack",
"build:node": "build_target=node webpack",
"build:es5": "build_target=web NODE_ENV=es5 webpack",
"build": "rm -rf ./dist && npm run build:browser && npm run build:node && npm run build:es5",
"build:providers": "build_target=web NODE_ENV=providers webpack",
"build": "rm -rf ./dist && npm run build:browser && npm run build:node && npm run build:providers",
"test:rpc": "cross-env NODE_ENV=test nyc mocha --compilers ts:ts-node/register -r tsconfig-paths/register test/RPC/index.js --no-timeouts",
"test:w": "cross-env NODE_ENV=testWatch mocha --compilers ts:ts-node/register -r tsconfig-paths/register test/index.js --require @babel/register -w --no-timeouts",
"test": "cross-env NODE_ENV=test nyc mocha --compilers ts:ts-node/register -r tsconfig-paths/register test/index.js --no-timeouts",
Expand Down
15 changes: 14 additions & 1 deletion src/Wallet/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ class Account {
});
return this._client.buildinLedger.sendRawTx(_callContractBlock, this.privateKey);
}

async mintageCancelPledge({
tokenId
}) {
const _callContractBlock = await this._client.buildinTxBlock.mintageCancelPledge({
accountAddress: this.address,
tokenId
});
return this._client.buildinLedger.sendRawTx(_callContractBlock, this.privateKey);
}

async mintageIssue({
tokenId, amount, beneficial
Expand All @@ -321,9 +331,12 @@ class Account {
return this._client.buildinLedger.sendRawTx(_callContractBlock, this.privateKey);
}

async mintageBurn() {
async mintageBurn({
amount, tokenId
}) {
const _callContractBlock = await this._client.buildinTxBlock.mintageBurn({
accountAddress: this.address,
amount, tokenId
});
return this._client.buildinLedger.sendRawTx(_callContractBlock, this.privateKey);
}
Expand Down
2 changes: 1 addition & 1 deletion src/client/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ledger as _ledger, onroad } from 'const/method';
import { RPCresponse, RPCrequest, BuiltinTxType, Address } from "const/type";
import { RPCrequest, BuiltinTxType, Address } from "const/type";
import { checkParams } from 'utils/tools';
import { validReqAccountBlock } from 'utils/builtin';
import { isValidHexAddr } from 'utils/address/privToAddr';
Expand Down
48 changes: 35 additions & 13 deletions src/client/txBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Vite_TokenId, Snapshot_Gid,
Quota_Addr, Vote_Addr, Register_Addr, Mintage_Addr,
Register_Abi, UpdateRegistration_Abi, CancelRegister_Abi,
Reward_Abi, Vote_Abi, CancelVote_Abi, Pledge_Abi, CancelPledge_Abi,
Mint_Abi, Issue_Abi, Burn_Abi, ChangeTokenType_Abi, TransferOwner_Abi } from "const/contract";
Mint_Abi, Issue_Abi, Burn_Abi, ChangeTokenType_Abi, TransferOwner_Abi, Mint_CancelPledge_Abi } from "const/contract";
import { SBPregBlock, block8, block7, revokeVotingBlock, quotaBlock,
sendTxBlock, receiveTxBlock, formatBlock,
createContractBlock, callContractBlock,
Expand Down Expand Up @@ -127,9 +127,9 @@ export default class tx {
}

async callContract({
accountAddress, toAddress, tokenId, amount, abi, methodName, params=[], height, prevHash, snapshotHash
accountAddress, toAddress, tokenId = Vite_TokenId, amount, abi, methodName, params=[], fee, height, prevHash, snapshotHash
}: callContractBlock, requestType = 'async') {
let err = checkParams({ toAddress, abi, tokenId }, ['toAddress', 'abi', 'tokenId']);
let err = checkParams({ toAddress, abi }, ['toAddress', 'abi']);
if (err) {
return Promise.reject(err);
}
Expand All @@ -140,7 +140,7 @@ export default class tx {
accountAddress,
toAddress,
data: Buffer.from(data, 'hex').toString('base64'),
height, prevHash, snapshotHash, tokenId, amount
height, fee, prevHash, snapshotHash, tokenId, amount
});
}

Expand Down Expand Up @@ -369,26 +369,41 @@ export default class tx {
return Promise.reject(err);
}

const spendAmount = '10000000000000000000000';
const spendFee = '1e21';
const spendAmount = '100000000000000000000000';
const spendFee = '1000000000000000000000';

let requestBlock = {
blockType: 2, toAddress: Mintage_Addr, accountAddress, height, prevHash, snapshotHash
}
requestBlock[spendType] = spendType === 'fee' ? spendFee : spendAmount;
let block = requestType === 'async' ? await this.asyncAccountBlock(requestBlock) : _getAccountBlock(requestBlock);

let tokenId = await this._client.mintage.newTokenId(accountAddress, block.height, block.prevHash, block.snapshotHash);
let tokenId = await this._client.mintage.newTokenId({
selfAddr: accountAddress,
height: block.height,
prevHash: block.prevHash,
snapshotHash: block.snapshotHash
});
let data = encodeFunctionCall(Mint_Abi, [isReIssuable, tokenId, tokenName, tokenSymbol, totalSupply, decimals, maxSupply, ownerBurnOnly]);
block.data = data;
block.data = Buffer.from(data, 'hex').toString('base64');

return block;
}

async mintageCancel({
async mintageCancelPledge({
accountAddress, tokenId, height, prevHash, snapshotHash
}: changeTokenTypeBlock, requestType = 'async') {
let err = checkParams({ tokenId }, ['tokenId'], [{ name: 'requestType', func: validReqType }]);
if (err) {
return Promise.reject(err);
}

}) {
return null;
return this.callContract({
abi: Mint_CancelPledge_Abi,
params: [tokenId],
toAddress: Mintage_Addr,
accountAddress, height, prevHash, snapshotHash
}, requestType);
}

async mintageIssue({
Expand All @@ -408,16 +423,23 @@ export default class tx {
abi: Issue_Abi,
toAddress: Mintage_Addr,
params: [tokenId, amount, beneficial],
accountAddress, height, prevHash, snapshotHash
accountAddress, amount: '0', height, prevHash, snapshotHash
}, requestType);
}

async mintageBurn({
accountAddress, height, prevHash, snapshotHash
accountAddress, tokenId, amount, height, prevHash, snapshotHash
}: mintageBurnBlock, requestType = 'async') {
let err = checkParams({ amount, requestType }, ['amount'], [{ name: 'requestType', func: validReqType }]);
if (err) {
return Promise.reject(err);
}

return this.callContract({
abi: Burn_Abi,
toAddress: Mintage_Addr,
fee: '0',
amount, tokenId,
accountAddress, height, prevHash, snapshotHash
}, requestType);
}
Expand Down
1 change: 1 addition & 0 deletions src/const/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export const Issue_Abi = {"type":"function","name":"Issue","inputs":[{"name":"to
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"}]};
3 changes: 3 additions & 0 deletions src/const/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ export declare type callContractBlock = {
toAddress: Address,
abi: object,
methodName?: string,
fee?: BigInt,
tokenId?: TokenId,
amount?: BigInt,
params?: Array<string>,
Expand Down Expand Up @@ -263,6 +264,8 @@ export declare type mintageIssueBlock = {

export declare type mintageBurnBlock = {
accountAddress: Address,
amount: BigInt,
tokenId: TokenId,
prevHash?: Hex,
height?: Uint64,
snapshotHash?: Hex
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import * as con from "./const";
import * as u from "./utils";
import c from "./client";
import * as w from "./Wallet";
import * as p from "./provider";

export const constant = con;
export const utils = u;
export const client = c;
export const wallet = w;
export const providers = p;
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// const merge = require('webpack-merge');
const env = process.env.NODE_ENV || 'development';

let envConfig = env === 'es5' ? require('./webpackConf/es5.config.js') : require('./webpackConf/base.config');
let envConfig = env === 'providers' ? require('./webpackConf/providers.config') : require('./webpackConf/base.config');

module.exports = envConfig;
12 changes: 2 additions & 10 deletions webpackConf/es5.config.js → webpackConf/providers.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@ const webpack = require('webpack');

const baseDir = path.resolve(process.cwd(), './src');
const target = process.env.build_target;
const Buffer_Path = path.join(__dirname, '../node_modules/buffer/index.js');

module.exports = {
plugins:[
new webpack.NormalModuleReplacementPlugin(/\/buffer\//, function(resource) {
resource.request = Buffer_Path;
}),
new webpack.DefinePlugin({
'processSilence': process.env.NODE_ENV && process.env.NODE_ENV.indexOf('test') === 0 ? 0 : 1
}),
],
target,
mode: 'production',
entry: {
client: path.resolve(baseDir, 'client/index.ts'),
const: path.resolve(baseDir, 'const/index.ts'),
providers: path.resolve(baseDir, 'provider/index.ts'),
WS: path.resolve(baseDir, 'provider/WS.js'),
HTTP: path.resolve(baseDir, 'provider/HTTP.js'),
IPC: path.resolve(baseDir, 'provider/IPC.js'),
utils: path.resolve(baseDir, 'utils/index.ts'),
wallet: path.resolve(baseDir, 'wallet/index.ts'),
IPC: path.resolve(baseDir, 'provider/IPC.js')
},
output: {
libraryTarget: 'umd',
umdNamedDefine: true,
filename:'[name].js',
path: path.join(__dirname, '../dist/es5'),
path: path.join(__dirname, '../dist/providers'),
},
optimization: {
splitChunks: {
Expand Down

0 comments on commit 1f0c733

Please sign in to comment.