diff --git a/src/neo/neoEngine.js b/src/neo/neoEngine.js index 402a2368a..0ea7ada5e 100644 --- a/src/neo/neoEngine.js +++ b/src/neo/neoEngine.js @@ -36,12 +36,12 @@ type NeoFunction = | 'neo_getBlockCount' | 'neo_broadcastTx' | 'neo_getTxHeight' - | 'neo_getTxOut' + // | 'neo_getTxOut' | 'neo_getBlock' export class NeoEngine extends CurrencyEngine { async multicastServers(func: NeoFunction, ...params: any): Promise { - this.log(`start to query ${func} on Neo Blockchain`) + // this.log(`start to query ${func} on Neo Blockchain`) const out = { result: '', server: 'no server' } switch (func) { case 'neo_getBalance': { @@ -73,9 +73,9 @@ export class NeoEngine extends CurrencyEngine { const client = new RPCClient(node) promises.push(client.sendRawTransaction(transaction)) } - const response = (await promiseAny(promises)).json() - if (response && response.result) { - return response.result + const response = await promiseAny(promises) + if (response) { + return response } else { throw new Error('NEO send fail with error: ' + response.error.message) } @@ -89,8 +89,8 @@ export class NeoEngine extends CurrencyEngine { promises.push(client.getRawTransaction(txId, 1)) } const response = await promiseAny(promises) - if (response && response.result) { - return response.result + if (response) { + return response } else { throw new Error( 'NEO get TX fail with error: ' + response.error.message @@ -122,32 +122,31 @@ export class NeoEngine extends CurrencyEngine { }) ) } - const response = (await promiseAny(promises)).json() - if (response && response.result) { - return response.result - } else { - throw new Error( - 'NEO get transaction height fail with error: ' + - response.error.message - ) - } - } - case 'neo_getTxOut': { - const rpcNodes = this.currencyInfo.defaultSettings.neoRpcNodes - const promises = [] - for (const node of rpcNodes) { - const client = new RPCClient(node) - promises.push(client.getTxOut(...params)) - } - const response = (await promiseAny(promises)).json() + const response = await promiseAny(promises) if (response && response.result) { return response.result } else { throw new Error( - 'NEO get tx outputs with error: ' + response.error.message + 'NEO get transaction height fail with error: ' + response.error.message ) } } + // case 'neo_getTxOut': { + // const rpcNodes = this.currencyInfo.defaultSettings.neoRpcNodes + // const promises = [] + // for (const node of rpcNodes) { + // const client = new RPCClient(node) + // promises.push(client.getTxOut(...params)) + // } + // const response = await promiseAny(promises) + // if (response) { + // return response + // } else { + // throw new Error( + // 'NEO get tx outputs with error: ' + response + // ) + // } + // } case 'neo_getBlock': { const rpcNodes = this.currencyInfo.defaultSettings.neoRpcNodes const promises = [] @@ -155,9 +154,9 @@ export class NeoEngine extends CurrencyEngine { const client = new RPCClient(node) promises.push(client.getBlock(...params)) } - const response = (await promiseAny(promises)).json() - if (response && response.result) { - return response.result + const response = await promiseAny(promises) + if (response) { + return response } else { throw new Error( 'NEO get tx outputs with error: ' + response.error.message @@ -203,9 +202,7 @@ export class NeoEngine extends CurrencyEngine { } async checkAccountInnerLoop() { - const address = wallet.getAddressFromScriptHash( - wallet.getScriptHashFromPublicKey(this.walletLocalData.publicKey) - ) + const address = this.walletLocalData.publicKey try { const balances = (await this.multicastServers('neo_getBalance', address)) @@ -239,13 +236,12 @@ export class NeoEngine extends CurrencyEngine { const neoInputs = [] for (let i = 0; i < vin.length; i++) { const { txid: prevHash, vout: prevIndex } = vin[i] - const from = await this.multicastServers( - 'neo_getTxOut', - prevHash, - prevIndex - ) - if (from.asset === currencyInfo.defaultSettings.assets.NEO) { - neoInputs.push(from) + const prevTx = await this.multicastServers('neo_getTx', prevHash) + if (prevTx && prevTx.vout) { + const from = prevTx.vout[prevIndex] + if (from.asset === currencyInfo.defaultSettings.assets.NEO) { + neoInputs.push(from) + } } } @@ -257,8 +253,14 @@ export class NeoEngine extends CurrencyEngine { const nativeAmount = neoOutputs.reduce((sum, cur) => sum + cur.value, 0) - const from = neoInputs[0].address - const to = [neoOutputs[0].address] + const from = [] + if (neoInputs.length > 0) { + from.push(neoInputs[0].address) + } + const to = [] + if (neoOutputs.length > 0) { + to.push(neoOutputs[0].address) + } const otherParams = { from, @@ -413,7 +415,7 @@ export class NeoEngine extends CurrencyEngine { if (currencyCode === PRIMARY_CURRENCY) { const neoParams: NeoTxOtherParams = { - from: this.walletLocalData.publicKey, + from: [this.walletLocalData.publicKey], to: [publicAddress], networkFee, isNative: true, @@ -430,7 +432,7 @@ export class NeoEngine extends CurrencyEngine { const contractAddress = tokenInfo.contractAddress const neoParams: NeoTxOtherParams = { - from: this.walletLocalData.publicKey, + from: [this.walletLocalData.publicKey], to: [publicAddress], networkFee, isNative: false, diff --git a/src/neo/neoInfo.js b/src/neo/neoInfo.js index 0bde8ef10..1bcefbc7f 100644 --- a/src/neo/neoInfo.js +++ b/src/neo/neoInfo.js @@ -19,7 +19,7 @@ export const currencyInfo: EdgeCurrencyInfo = { // Basic currency information: currencyCode: 'NEO', displayName: 'NEO', - pluginName: 'neo', + pluginId: 'neo', walletType: 'wallet:neo', defaultSettings, diff --git a/src/neo/neoSchema.js b/src/neo/neoSchema.js index 7193b493c..31eabbde1 100644 --- a/src/neo/neoSchema.js +++ b/src/neo/neoSchema.js @@ -1,4 +1,4 @@ -export const NeoTransactonOnline = { +export const NeoTransactionOnline = { type: 'object', properties: { txid: { type: 'string' }, @@ -23,13 +23,13 @@ export const NeoTransactonOnline = { properties: { n: { type: 'number' }, asset: { type: 'string' }, - value: { type: 'number' }, + value: { type: 'string' }, address: { type: 'string' } } } }, - sys_fee: { type: 'number' }, - net_fee: { type: 'number' }, + sys_fee: { type: 'string' }, + net_fee: { type: 'string' }, scripts: { type: 'array', items: { diff --git a/test/engine/fixtures.js b/test/engine/fixtures.js index c91833aa7..075972381 100644 --- a/test/engine/fixtures.js +++ b/test/engine/fixtures.js @@ -1,6 +1,6 @@ export default [ { - pluginName: 'neo', + pluginId: 'neo', WALLET_TYPE: 'wallet:neo', 'Test Currency code': 'NEO', key: [ @@ -39,7 +39,7 @@ export default [ ] }, { - pluginName: 'ripple', + pluginId: 'ripple', WALLET_TYPE: 'wallet:ripple', 'Test Currency code': 'XRP', key: [ diff --git a/test/plugin/fixtures.js b/test/plugin/fixtures.js index 48345dbac..9e282325b 100644 --- a/test/plugin/fixtures.js +++ b/test/plugin/fixtures.js @@ -1,6 +1,6 @@ export default [ { - pluginName: 'neo', + pluginId: 'neo', WALLET_TYPE: 'wallet:neo', 'Test Currency code': 'NEO', key: [ @@ -140,7 +140,7 @@ export default [ } }, { - pluginName: 'binance', + pluginId: 'binance', WALLET_TYPE: 'wallet:binance', 'Test Currency code': 'BNB', key: [