From e26059a0490f19e2995f4e0c7d96bb2bd7f3fe5a Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:46:00 +0800 Subject: [PATCH 01/21] add parameter type Long; --- package.json | 2 +- src/api/accountApi.ts | 2 +- src/background/api/smartContractApi.ts | 2 ++ src/background/api/tokenApi.ts | 1 + src/redux/settings.ts | 6 +++++- yarn.lock | 8 ++++---- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 9b8ada0..487bb4b 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@bugsnag/plugin-react": "^5.1.0", "@ont-community/hdkey-secp256r1": "^1.0.1", "@ont-community/ontology-ts-sdk-ledger": "^1.0.8", - "@ont-dev/ontology-dapi": "^0.4.9", + "@ont-dev/ontology-dapi": "^0.5.0", "autoprefixer": "7.1.6", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 19094f7..087664e 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null) { + if (defaultAddress != null || defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { diff --git a/src/background/api/smartContractApi.ts b/src/background/api/smartContractApi.ts index f78eff8..ae54bda 100644 --- a/src/background/api/smartContractApi.ts +++ b/src/background/api/smartContractApi.ts @@ -215,6 +215,8 @@ function convertParam(parameter: Parameter): Param { return new Param('', ParameterType.ByteArray, parameter.value) } else if (parameter.type === 'String') { return new Param('', ParameterType.String, parameter.value) + } else if (parameter.type === 'Long') { + return new Param('', ParameterType.Long, parameter.value) } else if (parameter.type === 'Array') { return new Param('', ParameterType.Array, convertParams(parameter.value)); } else if (parameter.type === 'Map') { diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index cb464ea..c95139d 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -18,6 +18,7 @@ export async function getOEP4Token(contract: string): Promise { } contract = utils.reverseHex(contract); +// TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; const builder = new Oep4TxBuilder(new Address(contract)); const client = getClient(); diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 9af3d89..491cb0b 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -15,6 +15,9 @@ * You should have received a copy of the GNU Lesser General Public License * along with The Ontology Wallet&ID. If not, see . */ + +import { VmType } from '@ont-dev/ontology-dapi'; + export type NetValue = 'TEST' | 'MAIN' | 'PRIVATE'; // tslint:disable:object-literal-sort-keys @@ -76,7 +79,8 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, + specification, + vmType: }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); diff --git a/yarn.lock b/yarn.lock index cb17dba..9bbd498 100644 --- a/yarn.lock +++ b/yarn.lock @@ -398,10 +398,10 @@ version "0.2.14" resolved "https://registry.yarnpkg.com/@ont-community/window-post-message-proxy/-/window-post-message-proxy-0.2.14.tgz#e3b1fe1b1558d7aedbbc1d0053e35f21cd9dc05e" -"@ont-dev/ontology-dapi@^0.4.9": - version "0.4.9" - resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.4.9.tgz#3ddde4e037f8820cf85fc885d2d1efb685937df9" - integrity sha512-9FJYzrLv1VzbS8vQZxnAOWtYJRx6kwzuNeY1USXWo6bIWGNt9i9UVYxKPJkhyVQj/hRn4YQz0q7W0Fpm6mjnPQ== +"@ont-dev/ontology-dapi@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.5.0.tgz#12007ac71daa63da8822f763f7dfda44cab7328d" + integrity sha512-KgTzElwnwkLjfCW+cX3nWeB7sC+KhJye5ogJONRXr84mFpdgq+y28chcks80yopr5zSN28yAM/cIgIx6HocSJA== dependencies: "@ont-community/window-post-message-proxy" "^0.2.14" base-x "^3.0.5" From 5a84effbae34fab9b1437533d3aac39791a200b5 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:51:30 +0800 Subject: [PATCH 02/21] fix tslint error; --- src/redux/settings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 491cb0b..aafee16 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -79,8 +79,7 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, - vmType: + specification }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); From 9cdf2ee57164379f1c4f374f0ea74a428f05ef41 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 12:01:49 +0800 Subject: [PATCH 03/21] fix import wallet error --- src/api/accountApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 087664e..ac9bbd0 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null || defaultAddress !== '') { + if (defaultAddress != null && defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { From cc7320367b56c21993b5d66d970e908cbf49d92a Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 19:34:47 +0800 Subject: [PATCH 04/21] update verison --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 487bb4b..a99db84 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lodash": "^4.17.10", "long": "^4.0.0", "object-assign": "4.1.1", - "ontology-ts-sdk": "^1.0.24", + "ontology-ts-sdk": "^1.0.25", "ontology-ts-test": "^0.2.37", "postcss-flexbugs-fixes": "3.2.0", "promise": "8.0.1", diff --git a/yarn.lock b/yarn.lock index 9bbd498..30a0dda 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6728,10 +6728,10 @@ ontology-ts-sdk@^0.9.4: wif "^2.0.6" ws "^4.1.0" -ontology-ts-sdk@^1.0.24: - version "1.0.24" - resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.24.tgz#5fd403ef9aac3931d54a25e4a323c1e500c42fca" - integrity sha512-jk+B2QbbE3uYgBvCkdwcJodHJYkxfmb1Km6RsxK2yM6E6krp7h7y01WCvLuEk2bgWTayz/jIg7AizeUqeRVlyg== +ontology-ts-sdk@^1.0.25: + version "1.0.25" + resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.25.tgz#6b46ea7b626707fa833694b063ad9d22b43fb770" + integrity sha512-R80Y0Eapzm5klHdwCC/g+dvnnXo7C29/FgpSamLOUMVsQvSE/GVbVtHQtnVxrjKCyIDhtn4L2RxIMovFo+dSVQ== dependencies: "@ont-community/hdkey-secp256r1" "^1.0.1" "@ont-community/html5-websocket" "^2.0.2" From 153924a687b0e8d5ed9935faa9fcdd3e350e789f Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 23 Oct 2019 11:45:26 +0800 Subject: [PATCH 05/21] update version --- package.json | 2 +- public/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a99db84..6255f0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyano-wallet", - "version": "0.7.15", + "version": "0.7.17", "private": true, "scripts": { "lint": "tslint -p .", diff --git a/public/manifest.json b/public/manifest.json index 8464ce7..6679748 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.16", + "version": "0.7.17", "browser_action": { "default_title": "Open the wallet" From c848c9e88c650079268142e26c1c855ec3bc9785 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:46:00 +0800 Subject: [PATCH 06/21] add parameter type Long; --- package.json | 2 +- src/api/accountApi.ts | 2 +- src/background/api/smartContractApi.ts | 4 +++- src/background/api/tokenApi.ts | 1 + src/redux/settings.ts | 6 +++++- yarn.lock | 8 ++++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ae496b0..01789f2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@bugsnag/plugin-react": "^5.1.0", "@ont-community/hdkey-secp256r1": "^1.0.1", "@ont-community/ontology-ts-sdk-ledger": "^1.0.8", - "@ont-dev/ontology-dapi": "^0.4.9", + "@ont-dev/ontology-dapi": "^0.5.0", "autoprefixer": "7.1.6", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 19094f7..087664e 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null) { + if (defaultAddress != null || defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { diff --git a/src/background/api/smartContractApi.ts b/src/background/api/smartContractApi.ts index 63c68e2..11b3cec 100644 --- a/src/background/api/smartContractApi.ts +++ b/src/background/api/smartContractApi.ts @@ -212,7 +212,9 @@ function convertParam(parameter: Parameter): Param { // will use ontology-ts-sdk to build script code and it treats ByteArray as hex string; return new Param('', ParameterType.ByteArray, parameter.value); } else if (parameter.type === 'String') { - return new Param('', ParameterType.String, parameter.value); + return new Param('', ParameterType.String, parameter.value) + } else if (parameter.type === 'Long') { + return new Param('', ParameterType.Long, parameter.value) } else if (parameter.type === 'Array') { return new Param('', ParameterType.Array, convertParams(parameter.value)); } else if (parameter.type === 'Map') { diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index cb464ea..c95139d 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -18,6 +18,7 @@ export async function getOEP4Token(contract: string): Promise { } contract = utils.reverseHex(contract); +// TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; const builder = new Oep4TxBuilder(new Address(contract)); const client = getClient(); diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 9af3d89..491cb0b 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -15,6 +15,9 @@ * You should have received a copy of the GNU Lesser General Public License * along with The Ontology Wallet&ID. If not, see . */ + +import { VmType } from '@ont-dev/ontology-dapi'; + export type NetValue = 'TEST' | 'MAIN' | 'PRIVATE'; // tslint:disable:object-literal-sort-keys @@ -76,7 +79,8 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, + specification, + vmType: }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); diff --git a/yarn.lock b/yarn.lock index 0e341c2..5e8016e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -398,10 +398,10 @@ version "0.2.14" resolved "https://registry.yarnpkg.com/@ont-community/window-post-message-proxy/-/window-post-message-proxy-0.2.14.tgz#e3b1fe1b1558d7aedbbc1d0053e35f21cd9dc05e" -"@ont-dev/ontology-dapi@^0.4.9": - version "0.4.9" - resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.4.9.tgz#3ddde4e037f8820cf85fc885d2d1efb685937df9" - integrity sha512-9FJYzrLv1VzbS8vQZxnAOWtYJRx6kwzuNeY1USXWo6bIWGNt9i9UVYxKPJkhyVQj/hRn4YQz0q7W0Fpm6mjnPQ== +"@ont-dev/ontology-dapi@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.5.0.tgz#12007ac71daa63da8822f763f7dfda44cab7328d" + integrity sha512-KgTzElwnwkLjfCW+cX3nWeB7sC+KhJye5ogJONRXr84mFpdgq+y28chcks80yopr5zSN28yAM/cIgIx6HocSJA== dependencies: "@ont-community/window-post-message-proxy" "^0.2.14" base-x "^3.0.5" From a7c770615a8479b40c8ea4590ced8bfa3233537f Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:51:30 +0800 Subject: [PATCH 07/21] fix tslint error; --- src/redux/settings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 491cb0b..aafee16 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -79,8 +79,7 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, - vmType: + specification }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); From 5277a15fac339f938a79c37d10e5baaa1f122118 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 12:01:49 +0800 Subject: [PATCH 08/21] fix import wallet error --- src/api/accountApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 087664e..ac9bbd0 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null || defaultAddress !== '') { + if (defaultAddress != null && defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { From 227832ba70e813b371d42bc2b80d4d099cf15866 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 19:34:47 +0800 Subject: [PATCH 09/21] update verison --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 01789f2..369a86f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lodash": "^4.17.10", "long": "^4.0.0", "object-assign": "4.1.1", - "ontology-ts-sdk": "^1.0.24", + "ontology-ts-sdk": "^1.0.25", "ontology-ts-test": "^0.2.37", "postcss-flexbugs-fixes": "3.2.0", "promise": "8.0.1", diff --git a/yarn.lock b/yarn.lock index 5e8016e..9dabc48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6728,10 +6728,10 @@ ontology-ts-sdk@^0.9.4: wif "^2.0.6" ws "^4.1.0" -ontology-ts-sdk@^1.0.24: - version "1.0.24" - resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.24.tgz#5fd403ef9aac3931d54a25e4a323c1e500c42fca" - integrity sha512-jk+B2QbbE3uYgBvCkdwcJodHJYkxfmb1Km6RsxK2yM6E6krp7h7y01WCvLuEk2bgWTayz/jIg7AizeUqeRVlyg== +ontology-ts-sdk@^1.0.25: + version "1.0.25" + resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.25.tgz#6b46ea7b626707fa833694b063ad9d22b43fb770" + integrity sha512-R80Y0Eapzm5klHdwCC/g+dvnnXo7C29/FgpSamLOUMVsQvSE/GVbVtHQtnVxrjKCyIDhtn4L2RxIMovFo+dSVQ== dependencies: "@ont-community/hdkey-secp256r1" "^1.0.1" "@ont-community/html5-websocket" "^2.0.2" From b2de99ff14c31373ea7b8b6e51bdad3ffe08b3ba Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 23 Oct 2019 11:45:26 +0800 Subject: [PATCH 10/21] update version --- package.json | 2 +- public/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 369a86f..fe7a3c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyano-wallet", - "version": "0.7.16", + "version": "0.7.17", "private": true, "scripts": { "lint": "tslint -p .", diff --git a/public/manifest.json b/public/manifest.json index 8464ce7..6679748 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.16", + "version": "0.7.17", "browser_action": { "default_title": "Open the wallet" From 2120734d898fc0337314133c48b3d1453d85b87a Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 13 Nov 2019 10:46:11 +0800 Subject: [PATCH 11/21] support add wasm ope4 token --- package.json | 2 +- public/manifest.json | 2 +- src/api/tokenApi.ts | 4 +- src/background/api/tokenApi.ts | 85 +++++++++++++++++++++++++------ src/background/balanceProvider.ts | 2 +- src/redux/settings.ts | 6 +-- yarn.lock | 8 +-- 7 files changed, 82 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index fe7a3c6..e56716f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lodash": "^4.17.10", "long": "^4.0.0", "object-assign": "4.1.1", - "ontology-ts-sdk": "^1.0.25", + "ontology-ts-sdk": "^1.1.0", "ontology-ts-test": "^0.2.37", "postcss-flexbugs-fixes": "3.2.0", "promise": "8.0.1", diff --git a/public/manifest.json b/public/manifest.json index 6679748..ad7064c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.17", + "version": "0.7.18", "browser_action": { "default_title": "Open the wallet" diff --git a/src/api/tokenApi.ts b/src/api/tokenApi.ts index defeefb..2833924 100644 --- a/src/api/tokenApi.ts +++ b/src/api/tokenApi.ts @@ -1,10 +1,12 @@ +export type VmType = 'NEOVM' | 'WASMVM'; export interface OEP4Token { name: string; symbol: string; decimals: number; + vmType: VmType; } export interface OEP4TokenAmount extends OEP4Token { amount: string; -} \ No newline at end of file +} diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index c95139d..256b6e4 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -1,10 +1,10 @@ import * as Long from 'long'; -import { CONST, Crypto, Oep4, TransactionBuilder, utils } from 'ontology-ts-sdk'; +import { CONST, Crypto, Oep4, Parameter, ParameterType, TransactionBuilder, utils } from 'ontology-ts-sdk'; import { decryptAccount, getAccount } from 'src/api/accountApi'; import { encodeAmount } from 'src/popup/utils/number'; import { TransferRequest } from 'src/redux/transactionRequests'; import { getWallet } from '../../api/authApi'; -import { OEP4Token } from '../../api/tokenApi'; +import { OEP4Token, VmType } from '../../api/tokenApi'; import { getClient } from '../network'; import { getStore } from '../redux'; @@ -12,35 +12,77 @@ import Address = Crypto.Address; import Oep4TxBuilder = Oep4.Oep4TxBuilder; import { isHexadecimal } from 'src/api/utils'; +const gasPrice = '500'; +const gasLimit = '20000'; export async function getOEP4Token(contract: string): Promise { if (!isHexadecimal(contract)) { throw new Error('Contract is not hexadecimal string'); } - contract = utils.reverseHex(contract); + // TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; -// TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; - const builder = new Oep4TxBuilder(new Address(contract)); + const contractAddr = utils.reverseHex(contract); + const builder = new Oep4TxBuilder(new Address(contractAddr)); const client = getClient(); - const nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); - const symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); - const decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); + // first get contract json to decide the vmType + const contractJson = await client.getContractJson(contract); + let vmType: VmType = 'NEOVM'; + if (contractJson && contractJson.Error === 0) { + if (contractJson.Result && contractJson.Result.VmType === 3) { + vmType = 'WASMVM'; + } + } + let nameResponse; + let symbolResponse; + let decimalsResponse; + if (vmType === 'NEOVM') { + nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); + symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); + decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); + } else if (vmType === 'WASMVM') { + debugger + const tx1 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'name', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + nameResponse = await client.sendRawTransaction(tx1.serialize(), true); + const tx2 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'symbol', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + symbolResponse = await client.sendRawTransaction(tx2.serialize(), true); + const tx3 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'decimal', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + decimalsResponse = await client.sendRawTransaction(tx3.serialize(), true); + } return { decimals: extractNumberResponse(decimalsResponse), name: extractStringResponse(nameResponse), symbol: extractStringResponse(symbolResponse), + vmType, }; } -export async function getTokenBalanceOwn(contract: string) { +export async function getTokenBalanceOwn(contract: string, vmType: VmType) { const state = getStore().getState(); const address = getAccount(state.wallet.wallet!).address; - return getTokenBalance(contract, address); + return getTokenBalance(contract, address, vmType); } -export async function getTokenBalance(contract: string, address: Address) { +export async function getTokenBalance(contract: string, address: Address, vmType: VmType) { const state = getStore().getState(); const token = state.settings.tokens.find((t) => t.contract === contract); @@ -49,12 +91,23 @@ export async function getTokenBalance(contract: string, address: Address) { } contract = utils.reverseHex(contract); - - const builder = new Oep4TxBuilder(new Address(contract)); - const client = getClient(); - const tx = builder.queryBalanceOf(address); - const response = await client.sendRawTransaction(tx.serialize(), true); + let response; + if (vmType === 'NEOVM') { + const builder = new Oep4TxBuilder(new Address(contract)); + const tx = builder.queryBalanceOf(address); + response = await client.sendRawTransaction(tx.serialize(), true); + } else { + const params = [new Parameter('param1', ParameterType.Address, address)]; + const tx = TransactionBuilder.makeWasmVmInvokeTransaction( + 'balanceOf', + params, + new Address(contract), + gasPrice, + gasLimit, + ); + response = await client.sendRawTransaction(tx.serialize(), true); + } return Long.fromString(utils.reverseHex(response.Result.Result), true, 16).toString(); } diff --git a/src/background/balanceProvider.ts b/src/background/balanceProvider.ts index 96139f3..c917f78 100644 --- a/src/background/balanceProvider.ts +++ b/src/background/balanceProvider.ts @@ -37,7 +37,7 @@ export async function refreshBalance(store: GlobalStore) { for (const token of tokens) { try { - const amount = await getTokenBalanceOwn(token.contract); + const amount = await getTokenBalanceOwn(token.contract, token.vmType); tokenBalances.push({ contract: token.contract, amount }); } catch (e) { // tslint:disable-next-line:no-console diff --git a/src/redux/settings.ts b/src/redux/settings.ts index aafee16..6022df5 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -1,3 +1,4 @@ +import { VmType } from './../api/tokenApi'; /* * Copyright (C) 2018 Matus Zamborsky * This file is part of The Ontology Wallet&ID. @@ -16,8 +17,6 @@ * along with The Ontology Wallet&ID. If not, see . */ -import { VmType } from '@ont-dev/ontology-dapi'; - export type NetValue = 'TEST' | 'MAIN' | 'PRIVATE'; // tslint:disable:object-literal-sort-keys @@ -27,7 +26,8 @@ export interface TokenState { name: string; symbol: string; decimals: number; - specification: 'OEP-4'; + specification: 'OEP-4'; + vmType: VmType } export interface TrustedSc { diff --git a/yarn.lock b/yarn.lock index 9dabc48..8bf956f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6728,10 +6728,10 @@ ontology-ts-sdk@^0.9.4: wif "^2.0.6" ws "^4.1.0" -ontology-ts-sdk@^1.0.25: - version "1.0.25" - resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.25.tgz#6b46ea7b626707fa833694b063ad9d22b43fb770" - integrity sha512-R80Y0Eapzm5klHdwCC/g+dvnnXo7C29/FgpSamLOUMVsQvSE/GVbVtHQtnVxrjKCyIDhtn4L2RxIMovFo+dSVQ== +ontology-ts-sdk@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.1.0.tgz#7156220ec723c8ad23f3ae2f5c92374b2a9da55c" + integrity sha512-DaJBG2Ugi83TbWfaWY75ijoKuBQ6+7QAveVMfuY0UxrrzxWw9hXqK7UayvGugIfkRWivWr0dyvpHAkL605e6HQ== dependencies: "@ont-community/hdkey-secp256r1" "^1.0.1" "@ont-community/html5-websocket" "^2.0.2" From 4507dc474af3058ae0d61e100425e624a80fe4dd Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:46:00 +0800 Subject: [PATCH 12/21] add parameter type Long; --- package.json | 2 +- src/api/accountApi.ts | 2 +- src/background/api/smartContractApi.ts | 4 +++- src/background/api/tokenApi.ts | 1 + src/redux/settings.ts | 6 +++++- yarn.lock | 8 ++++---- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ae496b0..01789f2 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@bugsnag/plugin-react": "^5.1.0", "@ont-community/hdkey-secp256r1": "^1.0.1", "@ont-community/ontology-ts-sdk-ledger": "^1.0.8", - "@ont-dev/ontology-dapi": "^0.4.9", + "@ont-dev/ontology-dapi": "^0.5.0", "autoprefixer": "7.1.6", "axios": "^0.18.0", "babel-polyfill": "^6.26.0", diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 19094f7..087664e 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null) { + if (defaultAddress != null || defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { diff --git a/src/background/api/smartContractApi.ts b/src/background/api/smartContractApi.ts index 63c68e2..11b3cec 100644 --- a/src/background/api/smartContractApi.ts +++ b/src/background/api/smartContractApi.ts @@ -212,7 +212,9 @@ function convertParam(parameter: Parameter): Param { // will use ontology-ts-sdk to build script code and it treats ByteArray as hex string; return new Param('', ParameterType.ByteArray, parameter.value); } else if (parameter.type === 'String') { - return new Param('', ParameterType.String, parameter.value); + return new Param('', ParameterType.String, parameter.value) + } else if (parameter.type === 'Long') { + return new Param('', ParameterType.Long, parameter.value) } else if (parameter.type === 'Array') { return new Param('', ParameterType.Array, convertParams(parameter.value)); } else if (parameter.type === 'Map') { diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index cb464ea..c95139d 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -18,6 +18,7 @@ export async function getOEP4Token(contract: string): Promise { } contract = utils.reverseHex(contract); +// TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; const builder = new Oep4TxBuilder(new Address(contract)); const client = getClient(); diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 9af3d89..491cb0b 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -15,6 +15,9 @@ * You should have received a copy of the GNU Lesser General Public License * along with The Ontology Wallet&ID. If not, see . */ + +import { VmType } from '@ont-dev/ontology-dapi'; + export type NetValue = 'TEST' | 'MAIN' | 'PRIVATE'; // tslint:disable:object-literal-sort-keys @@ -76,7 +79,8 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, + specification, + vmType: }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); diff --git a/yarn.lock b/yarn.lock index 0e341c2..5e8016e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -398,10 +398,10 @@ version "0.2.14" resolved "https://registry.yarnpkg.com/@ont-community/window-post-message-proxy/-/window-post-message-proxy-0.2.14.tgz#e3b1fe1b1558d7aedbbc1d0053e35f21cd9dc05e" -"@ont-dev/ontology-dapi@^0.4.9": - version "0.4.9" - resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.4.9.tgz#3ddde4e037f8820cf85fc885d2d1efb685937df9" - integrity sha512-9FJYzrLv1VzbS8vQZxnAOWtYJRx6kwzuNeY1USXWo6bIWGNt9i9UVYxKPJkhyVQj/hRn4YQz0q7W0Fpm6mjnPQ== +"@ont-dev/ontology-dapi@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@ont-dev/ontology-dapi/-/ontology-dapi-0.5.0.tgz#12007ac71daa63da8822f763f7dfda44cab7328d" + integrity sha512-KgTzElwnwkLjfCW+cX3nWeB7sC+KhJye5ogJONRXr84mFpdgq+y28chcks80yopr5zSN28yAM/cIgIx6HocSJA== dependencies: "@ont-community/window-post-message-proxy" "^0.2.14" base-x "^3.0.5" From 026d8eba5ff5666ff5e9d1140c830edc5f264ee4 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:51:30 +0800 Subject: [PATCH 13/21] fix tslint error; --- src/redux/settings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 491cb0b..aafee16 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -79,8 +79,7 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, - vmType: + specification }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); From 9bd9305d9bb58a127a0eedd874a1cf088697dd54 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 12:01:49 +0800 Subject: [PATCH 14/21] fix import wallet error --- src/api/accountApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 087664e..ac9bbd0 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null || defaultAddress !== '') { + if (defaultAddress != null && defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { From 7a23afbe06a1833e4b519c2e5f33d5b53665daa6 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 19:34:47 +0800 Subject: [PATCH 15/21] update verison --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 01789f2..369a86f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lodash": "^4.17.10", "long": "^4.0.0", "object-assign": "4.1.1", - "ontology-ts-sdk": "^1.0.24", + "ontology-ts-sdk": "^1.0.25", "ontology-ts-test": "^0.2.37", "postcss-flexbugs-fixes": "3.2.0", "promise": "8.0.1", diff --git a/yarn.lock b/yarn.lock index 5e8016e..9dabc48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6728,10 +6728,10 @@ ontology-ts-sdk@^0.9.4: wif "^2.0.6" ws "^4.1.0" -ontology-ts-sdk@^1.0.24: - version "1.0.24" - resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.24.tgz#5fd403ef9aac3931d54a25e4a323c1e500c42fca" - integrity sha512-jk+B2QbbE3uYgBvCkdwcJodHJYkxfmb1Km6RsxK2yM6E6krp7h7y01WCvLuEk2bgWTayz/jIg7AizeUqeRVlyg== +ontology-ts-sdk@^1.0.25: + version "1.0.25" + resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.25.tgz#6b46ea7b626707fa833694b063ad9d22b43fb770" + integrity sha512-R80Y0Eapzm5klHdwCC/g+dvnnXo7C29/FgpSamLOUMVsQvSE/GVbVtHQtnVxrjKCyIDhtn4L2RxIMovFo+dSVQ== dependencies: "@ont-community/hdkey-secp256r1" "^1.0.1" "@ont-community/html5-websocket" "^2.0.2" From 3829577951673b7b9430a373b9e7156a671bf1b2 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 23 Oct 2019 11:45:26 +0800 Subject: [PATCH 16/21] update version --- package.json | 2 +- public/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 369a86f..fe7a3c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyano-wallet", - "version": "0.7.16", + "version": "0.7.17", "private": true, "scripts": { "lint": "tslint -p .", diff --git a/public/manifest.json b/public/manifest.json index 8464ce7..6679748 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.16", + "version": "0.7.17", "browser_action": { "default_title": "Open the wallet" From 7c2540b7b2f344d163c84811d82f8882b10e1eb5 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:46:00 +0800 Subject: [PATCH 17/21] add parameter type Long; --- src/api/accountApi.ts | 2 +- src/redux/settings.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index ac9bbd0..087664e 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null && defaultAddress !== '') { + if (defaultAddress != null || defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { diff --git a/src/redux/settings.ts b/src/redux/settings.ts index aafee16..491cb0b 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -79,7 +79,8 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification + specification, + vmType: }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); From 759e947f2a11ce03fabbf4a475d5aaf34c5d08e2 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 11:51:30 +0800 Subject: [PATCH 18/21] fix tslint error; --- src/redux/settings.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/redux/settings.ts b/src/redux/settings.ts index 491cb0b..aafee16 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -79,8 +79,7 @@ export const addToken = (contract: string, name: string, symbol: string, decimal name, symbol, decimals, - specification, - vmType: + specification }); export const delToken = (contract: string) => ({ type: DEL_TOKEN, contract }); From 603df96b5c281ee2a87dfa16bbce3dd95ed94175 Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Thu, 17 Oct 2019 12:01:49 +0800 Subject: [PATCH 19/21] fix import wallet error --- src/api/accountApi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/accountApi.ts b/src/api/accountApi.ts index 087664e..ac9bbd0 100644 --- a/src/api/accountApi.ts +++ b/src/api/accountApi.ts @@ -124,7 +124,7 @@ export function getAccount(wallet: string | Wallet) { const defaultAddress = wallet.defaultAccountAddress; - if (defaultAddress != null || defaultAddress !== '') { + if (defaultAddress != null && defaultAddress !== '') { const account = wallet.accounts.find((a) => a.address.toBase58() === defaultAddress); if (account === undefined) { From df343ba4b384716f51dd69609dd896340a29e45e Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 13 Nov 2019 10:46:11 +0800 Subject: [PATCH 20/21] support add wasm ope4 token --- package.json | 2 +- public/manifest.json | 2 +- src/api/tokenApi.ts | 4 +- src/background/api/tokenApi.ts | 85 +++++++++++++++++++++++++------ src/background/balanceProvider.ts | 2 +- src/redux/settings.ts | 6 +-- yarn.lock | 8 +-- 7 files changed, 82 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index fe7a3c6..e56716f 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "lodash": "^4.17.10", "long": "^4.0.0", "object-assign": "4.1.1", - "ontology-ts-sdk": "^1.0.25", + "ontology-ts-sdk": "^1.1.0", "ontology-ts-test": "^0.2.37", "postcss-flexbugs-fixes": "3.2.0", "promise": "8.0.1", diff --git a/public/manifest.json b/public/manifest.json index 6679748..ad7064c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.17", + "version": "0.7.18", "browser_action": { "default_title": "Open the wallet" diff --git a/src/api/tokenApi.ts b/src/api/tokenApi.ts index defeefb..2833924 100644 --- a/src/api/tokenApi.ts +++ b/src/api/tokenApi.ts @@ -1,10 +1,12 @@ +export type VmType = 'NEOVM' | 'WASMVM'; export interface OEP4Token { name: string; symbol: string; decimals: number; + vmType: VmType; } export interface OEP4TokenAmount extends OEP4Token { amount: string; -} \ No newline at end of file +} diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index c95139d..256b6e4 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -1,10 +1,10 @@ import * as Long from 'long'; -import { CONST, Crypto, Oep4, TransactionBuilder, utils } from 'ontology-ts-sdk'; +import { CONST, Crypto, Oep4, Parameter, ParameterType, TransactionBuilder, utils } from 'ontology-ts-sdk'; import { decryptAccount, getAccount } from 'src/api/accountApi'; import { encodeAmount } from 'src/popup/utils/number'; import { TransferRequest } from 'src/redux/transactionRequests'; import { getWallet } from '../../api/authApi'; -import { OEP4Token } from '../../api/tokenApi'; +import { OEP4Token, VmType } from '../../api/tokenApi'; import { getClient } from '../network'; import { getStore } from '../redux'; @@ -12,35 +12,77 @@ import Address = Crypto.Address; import Oep4TxBuilder = Oep4.Oep4TxBuilder; import { isHexadecimal } from 'src/api/utils'; +const gasPrice = '500'; +const gasLimit = '20000'; export async function getOEP4Token(contract: string): Promise { if (!isHexadecimal(contract)) { throw new Error('Contract is not hexadecimal string'); } - contract = utils.reverseHex(contract); + // TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; -// TODO 需要支持wasm vm的oep4;转账也要分NEO和wasm; - const builder = new Oep4TxBuilder(new Address(contract)); + const contractAddr = utils.reverseHex(contract); + const builder = new Oep4TxBuilder(new Address(contractAddr)); const client = getClient(); - const nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); - const symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); - const decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); + // first get contract json to decide the vmType + const contractJson = await client.getContractJson(contract); + let vmType: VmType = 'NEOVM'; + if (contractJson && contractJson.Error === 0) { + if (contractJson.Result && contractJson.Result.VmType === 3) { + vmType = 'WASMVM'; + } + } + let nameResponse; + let symbolResponse; + let decimalsResponse; + if (vmType === 'NEOVM') { + nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); + symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); + decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); + } else if (vmType === 'WASMVM') { + debugger + const tx1 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'name', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + nameResponse = await client.sendRawTransaction(tx1.serialize(), true); + const tx2 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'symbol', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + symbolResponse = await client.sendRawTransaction(tx2.serialize(), true); + const tx3 = TransactionBuilder.makeWasmVmInvokeTransaction( + 'decimal', + [], + new Address(contractAddr), + gasPrice, + gasLimit, + ); + decimalsResponse = await client.sendRawTransaction(tx3.serialize(), true); + } return { decimals: extractNumberResponse(decimalsResponse), name: extractStringResponse(nameResponse), symbol: extractStringResponse(symbolResponse), + vmType, }; } -export async function getTokenBalanceOwn(contract: string) { +export async function getTokenBalanceOwn(contract: string, vmType: VmType) { const state = getStore().getState(); const address = getAccount(state.wallet.wallet!).address; - return getTokenBalance(contract, address); + return getTokenBalance(contract, address, vmType); } -export async function getTokenBalance(contract: string, address: Address) { +export async function getTokenBalance(contract: string, address: Address, vmType: VmType) { const state = getStore().getState(); const token = state.settings.tokens.find((t) => t.contract === contract); @@ -49,12 +91,23 @@ export async function getTokenBalance(contract: string, address: Address) { } contract = utils.reverseHex(contract); - - const builder = new Oep4TxBuilder(new Address(contract)); - const client = getClient(); - const tx = builder.queryBalanceOf(address); - const response = await client.sendRawTransaction(tx.serialize(), true); + let response; + if (vmType === 'NEOVM') { + const builder = new Oep4TxBuilder(new Address(contract)); + const tx = builder.queryBalanceOf(address); + response = await client.sendRawTransaction(tx.serialize(), true); + } else { + const params = [new Parameter('param1', ParameterType.Address, address)]; + const tx = TransactionBuilder.makeWasmVmInvokeTransaction( + 'balanceOf', + params, + new Address(contract), + gasPrice, + gasLimit, + ); + response = await client.sendRawTransaction(tx.serialize(), true); + } return Long.fromString(utils.reverseHex(response.Result.Result), true, 16).toString(); } diff --git a/src/background/balanceProvider.ts b/src/background/balanceProvider.ts index 96139f3..c917f78 100644 --- a/src/background/balanceProvider.ts +++ b/src/background/balanceProvider.ts @@ -37,7 +37,7 @@ export async function refreshBalance(store: GlobalStore) { for (const token of tokens) { try { - const amount = await getTokenBalanceOwn(token.contract); + const amount = await getTokenBalanceOwn(token.contract, token.vmType); tokenBalances.push({ contract: token.contract, amount }); } catch (e) { // tslint:disable-next-line:no-console diff --git a/src/redux/settings.ts b/src/redux/settings.ts index aafee16..6022df5 100644 --- a/src/redux/settings.ts +++ b/src/redux/settings.ts @@ -1,3 +1,4 @@ +import { VmType } from './../api/tokenApi'; /* * Copyright (C) 2018 Matus Zamborsky * This file is part of The Ontology Wallet&ID. @@ -16,8 +17,6 @@ * along with The Ontology Wallet&ID. If not, see . */ -import { VmType } from '@ont-dev/ontology-dapi'; - export type NetValue = 'TEST' | 'MAIN' | 'PRIVATE'; // tslint:disable:object-literal-sort-keys @@ -27,7 +26,8 @@ export interface TokenState { name: string; symbol: string; decimals: number; - specification: 'OEP-4'; + specification: 'OEP-4'; + vmType: VmType } export interface TrustedSc { diff --git a/yarn.lock b/yarn.lock index 9dabc48..8bf956f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6728,10 +6728,10 @@ ontology-ts-sdk@^0.9.4: wif "^2.0.6" ws "^4.1.0" -ontology-ts-sdk@^1.0.25: - version "1.0.25" - resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.0.25.tgz#6b46ea7b626707fa833694b063ad9d22b43fb770" - integrity sha512-R80Y0Eapzm5klHdwCC/g+dvnnXo7C29/FgpSamLOUMVsQvSE/GVbVtHQtnVxrjKCyIDhtn4L2RxIMovFo+dSVQ== +ontology-ts-sdk@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/ontology-ts-sdk/-/ontology-ts-sdk-1.1.0.tgz#7156220ec723c8ad23f3ae2f5c92374b2a9da55c" + integrity sha512-DaJBG2Ugi83TbWfaWY75ijoKuBQ6+7QAveVMfuY0UxrrzxWw9hXqK7UayvGugIfkRWivWr0dyvpHAkL605e6HQ== dependencies: "@ont-community/hdkey-secp256r1" "^1.0.1" "@ont-community/html5-websocket" "^2.0.2" From e915a429047058ea6f037c1cf8410bf50d06660f Mon Sep 17 00:00:00 2001 From: MickeyWang <1244134672@qq.com> Date: Wed, 13 Nov 2019 14:49:24 +0800 Subject: [PATCH 21/21] support transfer wasm vm oep4 --- package.json | 2 +- public/manifest.json | 2 +- src/background/api/tokenApi.ts | 58 ++++++++++++------- src/background/redux/settingsReducer.ts | 1 + src/popup/pages/dashboard/dashboard.tsx | 1 + src/popup/pages/send/sendView.tsx | 2 +- .../tokenSettingsAdd/tokenSettingsAdd.tsx | 2 +- src/redux/settings.ts | 16 +++-- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index e56716f..2da7144 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyano-wallet", - "version": "0.7.17", + "version": "0.7.19", "private": true, "scripts": { "lint": "tslint -p .", diff --git a/public/manifest.json b/public/manifest.json index ad7064c..15840dd 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -4,7 +4,7 @@ "name": "Cyano wallet", "author": "Matus Zamborsky ", "description": "Cyano wallet - an Ontology wallet", - "version": "0.7.18", + "version": "0.7.19", "browser_action": { "default_title": "Open the wallet" diff --git a/src/background/api/tokenApi.ts b/src/background/api/tokenApi.ts index 256b6e4..6150495 100644 --- a/src/background/api/tokenApi.ts +++ b/src/background/api/tokenApi.ts @@ -35,12 +35,7 @@ export async function getOEP4Token(contract: string): Promise { let nameResponse; let symbolResponse; let decimalsResponse; - if (vmType === 'NEOVM') { - nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); - symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); - decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); - } else if (vmType === 'WASMVM') { - debugger + if (vmType === 'WASMVM') { const tx1 = TransactionBuilder.makeWasmVmInvokeTransaction( 'name', [], @@ -58,13 +53,17 @@ export async function getOEP4Token(contract: string): Promise { ); symbolResponse = await client.sendRawTransaction(tx2.serialize(), true); const tx3 = TransactionBuilder.makeWasmVmInvokeTransaction( - 'decimal', + 'decimals', [], new Address(contractAddr), gasPrice, gasLimit, ); decimalsResponse = await client.sendRawTransaction(tx3.serialize(), true); + } else { + nameResponse = await client.sendRawTransaction(builder.queryName().serialize(), true); + symbolResponse = await client.sendRawTransaction(builder.querySymbol().serialize(), true); + decimalsResponse = await client.sendRawTransaction(builder.queryDecimals().serialize(), true); } return { @@ -93,11 +92,7 @@ export async function getTokenBalance(contract: string, address: Address, vmType contract = utils.reverseHex(contract); const client = getClient(); let response; - if (vmType === 'NEOVM') { - const builder = new Oep4TxBuilder(new Address(contract)); - const tx = builder.queryBalanceOf(address); - response = await client.sendRawTransaction(tx.serialize(), true); - } else { + if (vmType === 'WASMVM') { const params = [new Parameter('param1', ParameterType.Address, address)]; const tx = TransactionBuilder.makeWasmVmInvokeTransaction( 'balanceOf', @@ -107,6 +102,10 @@ export async function getTokenBalance(contract: string, address: Address, vmType gasLimit, ); response = await client.sendRawTransaction(tx.serialize(), true); + } else { + const builder = new Oep4TxBuilder(new Address(contract)); + const tx = builder.queryBalanceOf(address); + response = await client.sendRawTransaction(tx.serialize(), true); } return Long.fromString(utils.reverseHex(response.Result.Result), true, 16).toString(); @@ -120,7 +119,6 @@ export async function transferToken(request: TransferRequest, password: string) if (token === undefined) { throw new Error('OEP-4 token not found.'); } - const contract = utils.reverseHex(token.contract); const builder = new Oep4TxBuilder(new Address(contract)); @@ -129,15 +127,31 @@ export async function transferToken(request: TransferRequest, password: string) const to = new Address(request.recipient); const amount = String(request.amount); - - const tx = builder.makeTransferTx( - from, - to, - encodeAmount(amount, token.decimals), - '500', - `${CONST.DEFAULT_GAS_LIMIT}`, - from, - ); + let tx; + if (token.vmType === 'WASMVM') { + const params = [ + new Parameter('from', ParameterType.Address, from), + new Parameter('to', ParameterType.Address, to), + new Parameter('amount', ParameterType.Long, encodeAmount(amount, token.decimals)) + ]; + tx = TransactionBuilder.makeWasmVmInvokeTransaction( + 'transfer', + params, + new Address(contract), + gasPrice, + `${CONST.DEFAULT_GAS_LIMIT}`, + from + ); + } else { + tx = builder.makeTransferTx( + from, + to, + encodeAmount(amount, token.decimals), + '500', + `${CONST.DEFAULT_GAS_LIMIT}`, + from, + ); + } await TransactionBuilder.signTransactionAsync(tx, privateKey); diff --git a/src/background/redux/settingsReducer.ts b/src/background/redux/settingsReducer.ts index 5e59b46..ec682d2 100644 --- a/src/background/redux/settingsReducer.ts +++ b/src/background/redux/settingsReducer.ts @@ -48,6 +48,7 @@ export const settingsReducer: Reducer = (state = defaultState, ac name: action.name, specification: action.specification, symbol: action.symbol, + vmType: action.vmType }, ], }; diff --git a/src/popup/pages/dashboard/dashboard.tsx b/src/popup/pages/dashboard/dashboard.tsx index f69dcd3..6a41d83 100644 --- a/src/popup/pages/dashboard/dashboard.tsx +++ b/src/popup/pages/dashboard/dashboard.tsx @@ -121,6 +121,7 @@ function prepareTokenAmounts(tokens: TokenState[] = [], items: TokenAmountState[ decimals: token.decimals, name: token.name, symbol: token.symbol, + vmType: token.vmType, }; }); } diff --git a/src/popup/pages/send/sendView.tsx b/src/popup/pages/send/sendView.tsx index 36ae82b..1844c37 100644 --- a/src/popup/pages/send/sendView.tsx +++ b/src/popup/pages/send/sendView.tsx @@ -109,7 +109,7 @@ export const SendView: React.SFC = (props) => ( input={{ ...t.input, value: t.input.value }} error={t.meta.touched && t.meta.invalid} disabled={props.locked || get(formProps.values, 'asset') === undefined} - action={