Skip to content

Commit

Permalink
Merge pull request #2 from TRON-US/master
Browse files Browse the repository at this point in the history
Sync from orginal master
  • Loading branch information
shenyongri110 authored Oct 11, 2019
2 parents b24fa38 + 9324051 commit 8430b21
Show file tree
Hide file tree
Showing 20 changed files with 8,350 additions and 281 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ package-lock.json
test/setup/TronWeb.js
coverage
yarn-error.log
yarn.lock
/dist
.env
.vscode/
.idea/
example/
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
<a href="https://discord.gg/GsRgsTD">
<img src="https://img.shields.io/badge/chat-on%20discord-brightgreen.svg">
</a>

<a href="https://github.com/tron-us/tronweb/issues">
<img src="https://img.shields.io/github/issues/tron-us/tronweb.svg">
</a>

<a href="https://github.com/tron-us/tronweb/pulls">
<img src="https://img.shields.io/github/issues-pr/tron-us/tronweb.svg">
</a>

<a href="https://github.com/tron-us/tronweb/graphs/contributors">
<img src="https://img.shields.io/github/contributors/tron-us/tronweb.svg">
</a>

<a href="LICENSE">
<img src="https://img.shields.io/github/license/tron-us/tronweb.svg">
</a>
Expand All @@ -37,7 +37,7 @@ TronWeb aims to deliver a unified, seamless development experience influenced by
You can access either version specifically from the [dist](dist) folder.

TronWeb is also compatible with frontend frameworks such as:
- Angular
- Angular
- React
- Vue.

Expand Down Expand Up @@ -168,6 +168,19 @@ In order to contribute you can

## Recent History

__2.6.8__
* Support extension of transaction expiration
* Allow to add data to the transaction
* Many minor changes and fixes

__2.6.3__
* Support get unconfirmed transaction function

__2.6.0__
* Support trigger constant contract, clear abi and add account by id
* Add permission id option in functions related to creating transaction
* Support multi-sign without permission id

__2.5.6__
* Reverse PR #6

Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tronweb",
"version": "2.5.6",
"description": "JavaScript SDK that encapsulates the TRON Node HTTP API",
"version": "2.7.2",
"description": "JavaScript SDK that encapsulates the TRON HTTP API",
"main": "dist/TronWeb.node.js",
"scripts": {
"prepare": "npm run build",
Expand All @@ -10,23 +10,25 @@
"clean": "rimraf dist",
"newaccount": "node scripts/test-node.js && node test/helpers/newAccounts 50",
"test": "node scripts/test-node.js && node test/helpers/newAccounts 50 npm run-script newaccount && npx mocha 'test/**/*.test.js'",
"test-no-accounts": "node scripts/test-node.js && npx mocha 'test/**/*.test.js'",
"test:browser": "npm run-script newaccount && node scripts/test-browser.js && npx karma start --single-run --browsers ChromeHeadless",
"coverage": "npm run-script test:browser && npm run-script test",
"btest": "npm run build:dev && npm run test"
},
"husky": {
"hooks": {
"pre-push": "node ./scripts/pre-push.js"
"pre-commit": "node ./scripts/pre-commit.js"
}
},
"dependencies": {
"@babel/runtime": "^7.0.0",
"axios": "^0.18.0",
"axios": "^0.19.0",
"babel-runtime": "^6.26.0",
"bignumber.js": "^7.2.1",
"elliptic": "^6.4.1",
"ethers": "^4.0.7",
"eventemitter3": "^3.1.0",
"lodash": "^4.17.14",
"semver": "^5.6.0",
"validator": "^10.7.1"
},
Expand All @@ -45,7 +47,7 @@
"chalk": "^2.4.1",
"eth-sig-util": "^2.1.0",
"globby": "^8.0.1",
"grunt": "^1.0.3",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.1",
"grunt-karma": "^3.0.0",
"husky": "^1.0.0-rc.14",
Expand Down
20 changes: 16 additions & 4 deletions scripts/pre-push.js → scripts/pre-commit.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
if (!process.env.SKIPPREPUSH) {
const {execSync, spawn} = require('child_process')
const path = require('path')
const fs = require('fs')
const resultFile = path.resolve(__dirname, '../pre-commit-result')

if (!process.env.SKIPPRECOMMIT) {

const {execSync, spawn} = require('child_process')
const chalk = require('chalk')

const branch = execSync('git name-rev --name-only HEAD').toString().split('\n')[0];
Expand All @@ -9,7 +13,6 @@ if (!process.env.SKIPPREPUSH) {
try {
unpushed = execSync(`git log origin/${branch}..${branch} --name-status`).toString().split('\n');
} catch (ex) {
// the branch hasn't ever been pushed
unpushed = execSync(`git log HEAD...origin --name-status`).toString().split('\n');
}

Expand Down Expand Up @@ -43,8 +46,17 @@ if (!process.env.SKIPPREPUSH) {
console.log(chalk.red('Tests have failed. Please verify tests are passing before pushing'));
process.exit(1);
}
if (fs.existsSync(resultFile)) {
fs.unlinkSync(resultFile)
}
execSync('git add -A')
process.exit(0);
})
})

} else {
console.log('echo "Test skipped before git commit" >> ' + resultFile)
fs.writeFileSync(resultFile, 'Test skipped before git commit.')
execSync('git add -A')
process.exit(0);
}

22 changes: 22 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import utils from 'utils';
import BigNumber from 'bignumber.js';
import EventEmitter from 'eventemitter3';
import {version} from '../package.json';
import semver from 'semver';

import TransactionBuilder from 'lib/transactionBuilder';
import Trx from 'lib/trx';
Expand All @@ -12,6 +13,8 @@ import Event from 'lib/event';
import {keccak256} from 'utils/ethersUtils';
import {ADDRESS_PREFIX} from 'utils/address';

const DEFAULT_VERSION = '3.5.0';

export default class TronWeb extends EventEmitter {
static providers = providers;
static BigNumber = BigNumber;
Expand Down Expand Up @@ -79,9 +82,22 @@ export default class TronWeb extends EventEmitter {
if (privateKey)
this.setPrivateKey(privateKey);

this.fullnodeVersion = DEFAULT_VERSION;
this.injectPromise = utils.promiseInjector(this);
}

async getFullnodeVersion() {
try {
const nodeInfo = await this.trx.getNodeInfo()
this.fullnodeVersion = nodeInfo.configNodeInfo.codeVersion
if (this.fullnodeVersion.split('.').length === 2) {
this.fullnodeVersion += '.0';
}
} catch (err) {
this.fullnodeVersion = DEFAULT_VERSION;
}
}

setDefaultBlock(blockID = false) {
if ([false, 'latest', 'earliest', 0].includes(blockID)) {
return this.defaultBlock = blockID;
Expand Down Expand Up @@ -124,6 +140,10 @@ export default class TronWeb extends EventEmitter {
this.emit('addressChanged', {hex, base58});
}

fullnodeSatisfies(version) {
return semver.satisfies(this.fullnodeVersion, version);
}

isValidProvider(provider) {
return Object.values(providers).some(knownProvider => provider instanceof knownProvider);
}
Expand All @@ -137,6 +157,8 @@ export default class TronWeb extends EventEmitter {

this.fullNode = fullNode;
this.fullNode.setStatusPage('wallet/getnowblock');

this.getFullnodeVersion();
}

setSolidityNode(solidityNode) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export default class Contract {
message: this.tronWeb.toUtf8(contract.message)
})

await utils.sleep(3000);
return this.at(signedTransaction.contract_address, callback);
} catch (ex) {
return callback(ex);
Expand Down
12 changes: 8 additions & 4 deletions src/lib/contract/method.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,15 @@ export default class Method {

const broadcast = await this.tronWeb.trx.sendRawTransaction(signedTransaction);

if (broadcast.code)
return callback({
if (broadcast.code) {
const err = {
error: broadcast.code,
message: this.tronWeb.toUtf8(broadcast.message)
})
message: broadcast.code
};
if (broadcast.message)
err.message = this.tronWeb.toUtf8(broadcast.message);
return callback(err)
}

if (!options.shouldPollResponse)
return callback(null, signedTransaction.txID);
Expand Down
Loading

0 comments on commit 8430b21

Please sign in to comment.