Skip to content

Commit

Permalink
Merge pull request #142 from phetter/development
Browse files Browse the repository at this point in the history
sendAsset Bugfix
  • Loading branch information
fetter committed Aug 26, 2018
2 parents f0ad727 + 9b6c92a commit 3a6312a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"write-file-webpack-plugin": "3.4.2"
},
"dependencies": {
"@cityofzion/neon-js": "git+https://github.com/cityofzion/neon-js.git#3.8.1",
"@cityofzion/neon-js": "^3.10.1",
"babel-plugin-react-css-modules": "^3.3.2",
"bignumber.js": "5.0.0",
"bluebird": "^3.3.4",
Expand Down
2 changes: 1 addition & 1 deletion src/app/containers/Send/Send.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export class Send extends Component {
this.setState({
loading: false,
showConfirmation: false,
txid: result.txid,
txid: result,
})
reset()
})
Expand Down
87 changes: 41 additions & 46 deletions src/app/utils/api/neon.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,65 +145,60 @@ export const getScriptHashFromAddress = (address) => {
* @return {Promise<Response>} RPC Response
*/
export const sendAsset = (netUrl, toAddress, account, wif, assetAmounts, remark, txFee, signingFunction) => {
// = (net, toAddress, from, assetAmounts, signingFunction) => {
let fee

if (txFee) fee = txFee
else fee = 0

const rpcEndpointPromise = api.neoscan.getRPCEndpoint(netUrl)
return api.neoscan.getBalance(netUrl, account.address).then(balance => {
logDeep('balance: ', balance)

const balancePromise = api.neoscan.getBalance(netUrl, account.address)
const scriptHash = getScriptHashFromAddress(toAddress)

// logDeep('account: ', account)
logDeep('scriptHash: ', scriptHash)

const scriptHash = getScriptHashFromAddress(toAddress)
if (remark) logDeep('remark: ', remark)

logDeep('scriptHash: ', scriptHash)
logDeep('remark: ', remark)
const intents = Object.keys(assetAmounts).map(key => {
return {
assetId: Neon.CONST.ASSET_ID[key],
value: assetAmounts[key],
scriptHash: scriptHash,
}
})

const intents = Object.keys(assetAmounts).map(key => {
return {
assetId: Neon.CONST.ASSET_ID[key],
value: assetAmounts[key],
scriptHash: scriptHash,
}
})
let signedTx
// let endpt
return Promise.all([rpcEndpointPromise, balancePromise])
.then(values => {
// endpt = values[0]
const balance = values[1]
// const unsignedTx = tx.Transaction.createContractTx(balance, intents)
const unsignedTx = tx.Transaction.createContractTx(balance, intents, {}, fee)
// const unsignedTx = tx.Transaction.createContractTx(balance, intents, {}, fee)
const unsignedTx = tx.Transaction.createContractTx(balance, intents, {}, fee)

if (remark) {
let uTx = unsignedTx.addRemark(remark)

logDeep('unsignedTx: ', uTx)
}

// if (signingFunction) {
// return signingFunction(unsignedTx, fromAcct.publicKey)
// } else {
// return unsignedTx.sign(fromAcct.privateKey)
// }
const myAccount = Neon.create.account(wif)
return unsignedTx.sign(myAccount.privateKey)
})
.then(signedResult => {
signedTx = signedResult
logDeep('signedTx: ', signedTx)
const client = Neon.create.rpcClient(netUrl)
return client.sendRawTransaction(signedTx)
})
.then(res => {
logDeep('tx Result: ', res)
if (res === true) {
res.txid = signedTx.hash
} else {
console.log(`Transaction failed: ${signedTx.serialize()}`)
}
return res
const myAccount = Neon.create.account(wif)

let signedTx = unsignedTx.sign(myAccount.privateKey)

logDeep('signedTx: ', signedTx)
console.log('hash: ' + signedTx.hash)

api.neoscan.getRPCEndpoint(netUrl).then(rpcEndpt => {
console.log('rpcEndpt: ' + rpcEndpt)

const client = Neon.create.rpcClient(rpcEndpt)

logDeep('client: ', client)

client.sendRawTransaction(signedTx).then(res => {
logDeep('tx Result: ', res)

if (res === true) {
return signedTx.hash
} else {
// console.log(`Transaction failed: ${signedTx.serialize()}`)
console.log('transaction failed')
}
return res
})
})
})
}

0 comments on commit 3a6312a

Please sign in to comment.