Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ad21415
fix can not send coin on test node when initializing the tronlink and…
unicornonea Nov 23, 2019
db021a4
change the way to new SunWeb
unicornonea Nov 23, 2019
808192d
Unexpected token
llwslc Nov 25, 2019
edd9caf
fix deposit button bug
llwslc Nov 25, 2019
0f6006e
merge
cathy-art Nov 25, 2019
515e6bb
update
cathy-art Nov 25, 2019
79c145e
update
cathy-art Nov 25, 2019
c065d0f
set address when init tronweb and sunweb
cathy-art Nov 26, 2019
94ac8d4
update
cathy-art Nov 26, 2019
d8bcc3d
update version to 3.2.3
cathy-art Nov 27, 2019
95d8506
get tokenID according to different chain
cathy-art Nov 27, 2019
a7d516d
modify json text trxmarket to Exchange
cathy-art Nov 27, 2019
d300eb8
update tronweb
cathy-art Dec 3, 2019
5484bc2
support multi sign confirmation
cathy-art Dec 3, 2019
a79bd64
change version to 3.2.4
cathy-art Dec 3, 2019
3d906cd
support transfer trc20 token when multi sign
cathy-art Dec 4, 2019
d8328c6
insert chainType into payload
cathy-art Dec 4, 2019
6cf3920
add multi sign link to tronscan for mainnet
cathy-art Dec 5, 2019
05ef286
set droplist height auto
cathy-art Dec 5, 2019
f8e89b2
fix cannot get account when add node
cathy-art Dec 5, 2019
6ae67d6
get net and energy for Dappchain
cathy-art Dec 5, 2019
28c202a
sign when input is string
cathy-art Dec 5, 2019
4f26907
modal body UI
cathy-art Dec 5, 2019
8f82876
fix token precision
Dec 12, 2019
0baeea6
change version to v3.2.5
unicornonea Dec 13, 2019
c31b774
add 10 token
unicornonea Dec 14, 2019
c8cbf54
add multi sign popup
unicornonea Dec 15, 2019
3ab7c61
add nile testnet
unicornonea Dec 16, 2019
b77bc19
add mainnet tronex node
unicornonea Dec 17, 2019
ffe5d33
delete tronex sidechain
unicornonea Dec 18, 2019
7564612
delete contract variables
unicornonea Dec 18, 2019
8424cea
change tronnex domain
unicornonea Dec 19, 2019
4ceba7f
format decimals as 6
unicornonea Dec 20, 2019
bfa0453
fix getSmartToken default balance error
llwslc Dec 20, 2019
6108819
support updateBrokerage type
unicornonea Dec 26, 2019
899b6cf
Merge branch 'feature/v3.2.5' of github.com:TronLink/tronlink-extensi…
unicornonea Dec 26, 2019
109ae72
change tronscan.org to tronscan.io
unicornonea Dec 30, 2019
1b39ca3
change detail link according to mainchain and dappchain
unicornonea Dec 31, 2019
b9b4c39
modify copywriter
unicornonea Jan 14, 2020
df4be2f
SETTING.TITLE.CURRENCY changed
unicornonea Jan 15, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "TronLink(波宝钱包)",
"version": "3.2.2",
"version_name": "3.2.2",
"version": "3.2.7",
"version_name": "3.2.7",
"description": "The first and most popular TRON wallet. Recommended by TRON Foundation.",
"author": "Kondax <kondaxsolutions@gmail.com>",
"content_security_policy": "script-src 'self' 'unsafe-eval' 'sha256-LayQc1iWBC+6WbHHvHZj3uSx3CxrGBHUJBR7si4qf8w=' 'sha256-POEO+wER89cezFVZ27JoP523HJNPMQxmh5Rcz/OZpr4=' 'sha256-IThiKMnsg0UHaLmP7sJxZpd/ohvINImwjxFJyxGFSlk=' https://*.sentry.io https://www.google-analytics.com https://www.googletagmanager.com https://cdnjs.cloudflare.com; object-src 'self'",
Expand Down
36 changes: 23 additions & 13 deletions packages/backgroundScript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const backgroundScript = {
duplex.on('getAllDapps', this.walletService.getAllDapps);
duplex.on('updateTokens', this.walletService.updateTokens);
duplex.on('getAllTokens', this.walletService.getAllTokens);
duplex.on('setMultiSignViewed', this.walletService.setMultiSignViewed);
duplex.on('setTransactionDetail', this.walletService.setTransactionDetail);
duplex.on('setAuthorizeDapps', this.walletService.setAuthorizeDapps);
duplex.on('getAuthorizeDapps', this.walletService.getAuthorizeDapps);
Expand Down Expand Up @@ -249,23 +250,22 @@ const backgroundScript = {
transaction,
input
} = data;

const {
selectedAccount
} = this.walletService;

let tronWeb = NodeService.tronWeb;
let chainType = 0;
if (!!transaction && transaction.chainType == 1) {
chainType = transaction.chainType;
if (!!transaction && data.input.chainType == 1) {
chainType = data.input.chainType;
// tronWeb = NodeService.sunWeb.sidechain;
}
const account = this.walletService.getAccount(selectedAccount);
const appWhitelist = this.walletService.appWhitelist.hasOwnProperty(hostname)?this.walletService.appWhitelist[ hostname ]:{};

if(typeof input === 'string') {
const { duration = 0 } = appWhitelist;
const signedTransaction = await account.sign(input);
const signedTransaction = !!data.multiSign ? await account.multiSign(transaction, Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain, data.permissionId) : await account.sign(input);
if(appWhitelist && (duration === -1 || duration >= Date.now())){
logger.info('Automatically signing transaction', signedTransaction);
return resolve({
Expand All @@ -281,30 +281,37 @@ const backgroundScript = {
input
}, uuid, resolve);
}

const contractType = transaction.raw_data.contract[ 0 ].type;
const contractAddress = TronWeb.address.fromHex(input.contract_address);
const {
mapped,
error
} = await transactionBuilder(Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain, contractType, input); // NodeService.getCurrentNode()
} = !!data.multiSign && data.permissionId != undefined ? {mapped: transaction, error: null} : await transactionBuilder(Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain, contractType, input); // NodeService.getCurrentNode()
if(error) {
return resolve({
success: false,
data: 'Invalid transaction provided',
uuid
});
}
const signedTransaction = await account.sign(
mapped.transaction || mapped,
Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain
);
let signedTransaction = {};
if (!!data.multiSign && data.permissionId != undefined) {
signedTransaction = await account.multiSign(
mapped.transaction || mapped,
Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain,
data.permissionId
)
} else {
signedTransaction = await account.sign(
mapped.transaction || mapped,
Number(chainType) === 1 ? NodeService.sunWeb.sidechain : NodeService.sunWeb.mainchain
);
}

const whitelist = this.walletService.contractWhitelist[ input.contract_address ];

if(contractType === 'TriggerSmartContract') {

// code bury

const value = input.call_value || 0;

ga('send', 'event', {
Expand Down Expand Up @@ -436,7 +443,10 @@ const backgroundScript = {
this.walletService.on('setNode', node => (
BackgroundAPI.setNode(node)
));


this.walletService.on('setMultiSignViewed', address => {
BackgroundAPI.setMultiSignViewed(address)
});

this.walletService.on('setChain', chain => (
BackgroundAPI.setChain(chain)
Expand Down
4 changes: 2 additions & 2 deletions packages/backgroundScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"bip39": "^2.5.0",
"buffer": "^5.2.1",
"eventemitter3": "^3.1.0",
"tronweb": "^2.7.4",
"sunweb": "^1.0.7"
"tronweb": "^2.8.1",
"sunweb": "^1.1.0"
},
"scripts": {
"build": "webpack --config ../../webpack.config.js --progress --colors -o ../../dist/backgroundScript.js",
Expand Down
161 changes: 126 additions & 35 deletions packages/backgroundScript/services/NodeService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import randomUUID from 'uuid/v4';
import TronWeb from 'tronweb';
import SunWeb from 'sunweb';
import Logger from '@tronlink/lib/logger';
import { CONTRACT_ADDRESS, SIDE_CHAIN_ID, NODE, SIDE_CHAIN_ID_TEST } from '@tronlink/lib/constants';
import { CONTRACT_ADDRESS, SIDE_CHAIN_ID, NODE, SIDE_CHAIN_ID_TEST, SIDE_CHAIN_ID_TEST_NILE} from '@tronlink/lib/constants';
import { BigNumber } from 'bignumber.js';

const logger = new Logger('NodeService');
Expand All @@ -20,54 +20,120 @@ const NodeService = {
}
},
_nodes: {
'3672f655-68a1-5c62-8929-d151c90ac21d': {
name: 'Mainnet',
'109c64ad-e59c-46fe-ba87-179587e6c772': {
name: 'Mainnet (trongrid)',
fullNode: 'https://api.trongrid.io',
solidityNode: 'https://api.trongrid.io',
eventServer: 'https://api.trongrid.io',
default: true, // false
chain: '_',
connect: '9dd662e3-052c-584d-9a13-df395a0d68f6'
connect: '51a36e5a-2480-4b57-989c-539345a13be2',
chainType: 0, // 0: Tron, 1: DappChain
netType: 0,
connectChain: {
fullNode: 'https://sun.tronex.io',
solidityNode: 'https://sun.tronex.io',
eventServer: 'https://sun.tronex.io',
mainGateway: CONTRACT_ADDRESS.MAIN,
sideGateway: CONTRACT_ADDRESS.SIDE,
chainId: SIDE_CHAIN_ID,
}
},
'8eeb5be6-5e10-4283-ae61-03c0e4726fe0': {
name: 'Mainnet (tronstack)',
fullNode: 'https://api.tronstack.io',
solidityNode: 'https://api.tronstack.io',
eventServer: 'https://api.trongrid.io',
default: false,
chain: '_',
// connect: '51a36e5a-2480-4b57-989c-539345a13be2',
chainType: 0, // 0: Tron, 1: DappChain
netType: 0, // 0: mainnet, 1: testnet
connectChain: false
},
'bb99520f-d86e-5722-92a3-e0bcbe409b3f': {
'b9424719-b45b-45aa-95d0-1b1b25fc75ae': {
name: 'Shasta Testnet',
fullNode: 'https://api.shasta.trongrid.io',
solidityNode: 'https://api.shasta.trongrid.io',
eventServer: 'https://api.shasta.trongrid.io',
default: false,
chain: '_',
chainType: 0,
netType: 1,
connectChain: false,
},
'9670cbd2-5289-57df-82c2-1c80b6bd8511': {
name: 'DappChain Testnet',
'f14212e2-a6a0-4391-9419-07b55f8be63e': {
name: 'Tronex Testnet',
fullNode: 'https://testhttpapi.tronex.io',
solidityNode: 'https://testhttpapi.tronex.io',
eventServer: 'https://testapi.tronex.io',
default: false,
chain: '_',
connect: '89895c8f-d355-5533-b9b3-d63f2408af7e'
connect: '01eda3a0-5a58-4e44-9f95-f7f1f59dd728',
chainType: 0,
netType: 1,
connectChain: {
fullNode: 'https://suntest.tronex.io',
solidityNode: 'https://suntest.tronex.io',
eventServer: 'https://suntest.tronex.io',
mainGateway: CONTRACT_ADDRESS.MAIN_TEST,
sideGateway: CONTRACT_ADDRESS.SIDE_TEST,
chainId: SIDE_CHAIN_ID_TEST,
}
},
'9dd662e3-052c-584d-9a13-df395a0d68f6': {
name: 'DappChain',
'910d7fa5-da35-419d-b454-fd4ee22087cd': {
name: 'Nile Testnet',
fullNode: 'https://api.nileex.io',
solidityNode: 'https://api.nileex.io',
eventServer: 'https://event.nileex.io',
default: false,
chain: '_',
chainType: 0,
netType: 1,
connectChain: false
},
'51a36e5a-2480-4b57-989c-539345a13be2': {
name: 'DappChain Mainnet',
fullNode: 'https://sun.tronex.io',
solidityNode: 'https://sun.tronex.io',
eventServer: 'https://sun.tronex.io',
default: true,
chain: SIDE_CHAIN_ID,
connect: '3672f655-68a1-5c62-8929-d151c90ac21d',
connect: '109c64ad-e59c-46fe-ba87-179587e6c772',
chainType: 1,
netType: 0,
mainGateway: CONTRACT_ADDRESS.MAIN,
sideGateway: CONTRACT_ADDRESS.SIDE,
sideChainId: SIDE_CHAIN_ID,
connectChain: {
fullNode: 'https://api.trongrid.io',
solidityNode: 'https://api.trongrid.io',
eventServer: 'https://api.trongrid.io',
}
},
'89895c8f-d355-5533-b9b3-d63f2408af7e': {
name: 'DappChain Testnet',
'01eda3a0-5a58-4e44-9f95-f7f1f59dd728': {
name: 'DappChain Tronex Testnet',
fullNode: 'https://suntest.tronex.io',
solidityNode: 'https://suntest.tronex.io',
eventServer: 'https://suntest.tronex.io',
default: false,
chain: SIDE_CHAIN_ID,
connect: '9670cbd2-5289-57df-82c2-1c80b6bd8511',
connect: 'f14212e2-a6a0-4391-9419-07b55f8be63e',
chainType: 1,
netType: 1,
mainGateway: CONTRACT_ADDRESS.MAIN_TEST,
sideGateway: CONTRACT_ADDRESS.SIDE_TEST,
sideChainId: SIDE_CHAIN_ID_TEST,
connectChain: {
fullNode: 'https://testhttpapi.tronex.io',
solidityNode: 'https://testhttpapi.tronex.io',
eventServer: 'https://testapi.tronex.io',
}
},

},
_selectedChain: '_',
_selectedNode: '3672f655-68a1-5c62-8929-d151c90ac21d',
_selectedNode: '109c64ad-e59c-46fe-ba87-179587e6c772',
_read() {
logger.info('Reading nodes and chains from storage');

Expand Down Expand Up @@ -132,24 +198,47 @@ const NodeService = {
fullNode,
solidityNode,
eventServer,
chainType,
connectChain,
mainGateway,
sideGateway,
sideChainId,
} = this.getCurrentNode();

this.sunWeb = new SunWeb(
//{fullNode:'https://api.trongrid.io',solidityNode:'https://api.trongrid.io',eventServer:'https://api.trongrid.io'},
//{fullNode:'https://sun.tronex.io',solidityNode:'https://sun.tronex.io',eventServer:'https://sun.tronex.io'},
NODE.MAIN,
NODE.SIDE,
CONTRACT_ADDRESS.MAIN,
CONTRACT_ADDRESS.SIDE,
SIDE_CHAIN_ID
);

this.tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer
);

if (Number(chainType) === 0) {
this.tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer
);
if (connectChain) {
this.sunWeb = new SunWeb(
new TronWeb(
fullNode,
solidityNode,
eventServer,
), new TronWeb(
connectChain.fullNode,
connectChain.solidityNode,
connectChain.eventServer,
),
connectChain.mainGateway,
connectChain.sideGateway,
connectChain.chainId);
} else {
this.sunWeb.mainchain = new TronWeb(fullNode,
solidityNode,
eventServer,)
}
} else {
this.tronWeb = new TronWeb(connectChain.fullNode, connectChain.solidityNode, connectChain.eventServer);

this.sunWeb = new SunWeb(
new TronWeb(connectChain.fullNode, connectChain.solidityNode, connectChain.eventServer),
new TronWeb(fullNode, solidityNode, eventServer),
mainGateway,
sideGateway,
sideChainId);
}
if (!skipAddress) {
this.setAddress();
}
Expand All @@ -167,6 +256,8 @@ const NodeService = {
this.tronWeb.setAddress(
StorageService.selectedAccount
);
this.sunWeb.mainchain.setAddress(StorageService.selectedAccount);
this.sunWeb.sidechain.setAddress(StorageService.selectedAccount);
},

save() {
Expand Down Expand Up @@ -229,9 +320,9 @@ const NodeService = {

addNode(node) {
const nodeID = randomUUID();

this._nodes[nodeID] = {
...node,
chainType: 0,
default: false
};
this.save();
Expand All @@ -241,15 +332,15 @@ const NodeService = {
async getSmartToken(address) {
try {
let balance;
const contract = await this.tronWeb.contract().at(address);
const contract = await this._selectedChain === '_' ? await this.tronWeb.contract().at(address) : await this.sunWeb.sidechain.contract().at(address);
if (!contract.name && !contract.symbol && !contract.decimals) {
return false;
}
const d = await contract.decimals().call();
const name = await contract.name().call();
const symbol = await contract.symbol().call();
const decimals = typeof d === 'object' && d._decimals ? d : new BigNumber(d).toNumber();
const number = await contract.balanceOf(address).call();
const number = await contract.balanceOf(this.tronWeb.defaultAddress.base58).call();
if (number.balance) {
balance = new BigNumber(number.balance).toString();
} else {
Expand Down
Loading