Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashuaidehao committed Aug 14, 2020
1 parent 7f34a37 commit 562094b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 52 deletions.
88 changes: 45 additions & 43 deletions src/neo/neoEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
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': {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down Expand Up @@ -122,42 +122,41 @@ 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 = []
for (const node of rpcNodes) {
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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/neo/neoInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const currencyInfo: EdgeCurrencyInfo = {
// Basic currency information:
currencyCode: 'NEO',
displayName: 'NEO',
pluginName: 'neo',
pluginId: 'neo',
walletType: 'wallet:neo',

defaultSettings,
Expand Down
8 changes: 4 additions & 4 deletions src/neo/neoSchema.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const NeoTransactonOnline = {
export const NeoTransactionOnline = {
type: 'object',
properties: {
txid: { type: 'string' },
Expand All @@ -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: {
Expand Down
4 changes: 2 additions & 2 deletions test/engine/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
{
pluginName: 'neo',
pluginId: 'neo',
WALLET_TYPE: 'wallet:neo',
'Test Currency code': 'NEO',
key: [
Expand Down Expand Up @@ -39,7 +39,7 @@ export default [
]
},
{
pluginName: 'ripple',
pluginId: 'ripple',
WALLET_TYPE: 'wallet:ripple',
'Test Currency code': 'XRP',
key: [
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/fixtures.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default [
{
pluginName: 'neo',
pluginId: 'neo',
WALLET_TYPE: 'wallet:neo',
'Test Currency code': 'NEO',
key: [
Expand Down Expand Up @@ -140,7 +140,7 @@ export default [
}
},
{
pluginName: 'binance',
pluginId: 'binance',
WALLET_TYPE: 'wallet:binance',
'Test Currency code': 'BNB',
key: [
Expand Down

0 comments on commit 562094b

Please sign in to comment.