Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/hooks/useBCH.js
Show All 9 Lines | import { | ||||
parseXecSendValue, | parseXecSendValue, | ||||
generateOpReturnScript, | generateOpReturnScript, | ||||
generateTxInput, | generateTxInput, | ||||
generateTxOutput, | generateTxOutput, | ||||
signAndBuildTx, | signAndBuildTx, | ||||
getChangeAddressFromInputUtxos, | getChangeAddressFromInputUtxos, | ||||
signUtxosByAddress, | signUtxosByAddress, | ||||
getUtxoWif, | getUtxoWif, | ||||
toLegacyCash, | |||||
} from 'utils/cashMethods'; | } from 'utils/cashMethods'; | ||||
import cashaddr from 'ecashaddrjs'; | import cashaddr from 'ecashaddrjs'; | ||||
import ecies from 'ecies-lite'; | import ecies from 'ecies-lite'; | ||||
import wif from 'wif'; | import wif from 'wif'; | ||||
export default function useBCH() { | export default function useBCH() { | ||||
const SEND_BCH_ERRORS = { | const SEND_BCH_ERRORS = { | ||||
INSUFFICIENT_FUNDS: 0, | INSUFFICIENT_FUNDS: 0, | ||||
▲ Show 20 Lines • Show All 1,026 Lines • ▼ Show 20 Lines | const sendXec = async ( | ||||
optionalOpReturnMsg, | optionalOpReturnMsg, | ||||
isOneToMany, | isOneToMany, | ||||
destinationAddressAndValueArray, | destinationAddressAndValueArray, | ||||
destinationAddress, | destinationAddress, | ||||
sendAmount, | sendAmount, | ||||
encryptionFlag, | encryptionFlag, | ||||
airdropFlag, | airdropFlag, | ||||
airdropTokenId, | airdropTokenId, | ||||
Backendless, | |||||
aliasFlag, | |||||
) => { | ) => { | ||||
try { | try { | ||||
let txBuilder = new BCH.TransactionBuilder(); | let txBuilder = new BCH.TransactionBuilder(); | ||||
if (aliasFlag) { | |||||
// this is a tx sent via XNS namespace alias, look up eCash address | |||||
let queryBuilder = new Backendless.DataQueryBuilder(); | |||||
let queryString = | |||||
"alias = '" + destinationAddress.toLowerCase() + "'"; | |||||
queryBuilder.setWhereClause(queryString); | |||||
await Backendless.Data.of('xns') | |||||
.find(queryBuilder) | |||||
.then(function (foundAlias) { | |||||
if (foundAlias.length === 0) { | |||||
// no alias found | |||||
throw new Error( | |||||
'The alias ' + | |||||
destinationAddress + | |||||
' does not exist', | |||||
); | |||||
} else if (foundAlias.length === 1) { | |||||
// found an alias, should only be one unique match | |||||
destinationAddress = toLegacyCash( | |||||
foundAlias[0].ecashAddress, | |||||
); | |||||
} else { | |||||
// corrupt DB integrity | |||||
throw new Error('Invalid namespace data'); | |||||
} | |||||
}) | |||||
.catch(function (error) { | |||||
console.log('Namespace error: ' + error); | |||||
throw error; | |||||
}); | |||||
} | |||||
// parse the input value of XECs to send | // parse the input value of XECs to send | ||||
const value = parseXecSendValue( | const value = parseXecSendValue( | ||||
isOneToMany, | isOneToMany, | ||||
sendAmount, | sendAmount, | ||||
destinationAddressAndValueArray, | destinationAddressAndValueArray, | ||||
); | ); | ||||
const satoshisToSend = fromXecToSatoshis(value); | const satoshisToSend = fromXecToSatoshis(value); | ||||
▲ Show 20 Lines • Show All 172 Lines • Show Last 20 Lines |