Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const sendPayment = ({ publicKey, decryptSK, sequence, destinationId, amount, memoValue, issuerPK, assetType }) => {
let sourceKeys = StellarSdk.Keypair.fromSecret(decryptSK)
let transaction
var blockEQToken = new StellarSdk.Asset(assetType, issuerPK)
const isMemoText = () => {
return /[a-z]/i.test(memoValue)
}
var memoParam
if (memoValue.length > 0) {
memoParam = isMemoText() ? StellarSdk.Memo.text(memoValue.toString()) : StellarSdk.Memo.id(memoValue.toString())
}
return new Promise((resolve, reject) => {
server.loadAccount(destinationId)
// If the account is not found, then create a transaction for creating an account
.catch(error => {
console.log(error.name)
if (error.name === 'NotFoundError') {
resolve({
exists: false,
payload: error
})
}
})
// If there was no error, load up-to-date information on your account.
.then(() => server.loadAccount(publicKey))
sendAsset: sendAsset,
sendMax: record.source_amount,
destination: destInfo.id,
destAsset: destAsset,
destAmount: destAmount,
path: path
});
}
const builder = new StellarSdk
.TransactionBuilder(account)
.addOperation(operation)
.setTimeout(0);
if (this.send.memo_type) {
const memo = StellarSdk.Memo[this.send.memo_type](this.send.memo.toString());
builder.addMemo(memo);
}
const tx = builder.build();
return {
tx: tx,
network: currentAccount.network
};
})
.then(this.Reviewer.review)
function* buildTransaction({
amount, asset, destination, memo,
}) {
const account = yield select(getMasterAccount);
const accountKeypair = yield select(getKeypairFor);
const paymentOp = Operation.payment({
destination,
amount,
asset: assets[asset],
});
let tx = new TransactionBuilder(account);
if (memo) {
tx = tx.addMemo(new Memo(MemoText, memo));
}
tx = tx.addOperation(paymentOp).build();
tx.sign(accountKeypair);
return tx;
}
public static fromDgraph(node: ITransactionData) {
let memo: Memo = Memo.none();
if (node["memo.value"]) {
memo = new Memo(node["memo.type"]!, node["memo.value"]!);
}
return new Transaction({
id: node.id,
ledgerSeq: parseInt(node.seq, 10),
index: parseInt(node.index, 10),
memo,
feeAmount: node.fee_amount,
feeCharged: node.fee_charged,
success: node.success,
resultCode: node.result_code,
sourceAccount: node["account.source"][0].id,
timeBounds: [node["time_bounds.min"], node["time_bounds.max"]]
});
}
}
if(typeof c.name !== 'string') throw new Error('Invalid name.');
if(c.name.length > 100) throw new Error(`Too long name, max 100 characters. Got ${c.name.length}.`);
if(typeof c.details !== 'string') throw new Error('Invalid details.');
if(c.details.length > 10000) throw new Error(`Too long details, max 10000 characters. Got ${c.name.length}.`);
if(!moment(c.created, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')
if(!moment(c.updated, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')
switch(c.defaultMemoType) {
case(StellarSdk.MemoNone):
case(StellarSdk.MemoId):
case(StellarSdk.MemoText):
case(StellarSdk.MemoHash):
case(StellarSdk.MemoReturn): {
try {
new StellarSdk.Memo(c.defaultMemoType, c.defaultMemoValue)
} catch(e) {
throw new Error(`Invalid Memo type and value combination. Got "${c.defaultMemoType}" and "${c.defaultMemoValue}".`)
}
break;
}
default: {
throw new Error(`Invalid Memo type. Got ${c.defaultMemoType}.`)
}
}
}
const createPaymentTx = async (horizon: Server, account: Account, formValues: PaymentFormValues) => {
const asset = props.trustedAssets.find(trustedAsset => trustedAsset.equals(formValues.asset))
const federationRecord =
formValues.destination.indexOf("*") > -1 ? await lookupFederationRecord(formValues.destination) : null
const destination = federationRecord ? federationRecord.account_id : formValues.destination
const userMemo = createMemo(formValues)
const federationMemo =
federationRecord && federationRecord.memo && federationRecord.memo_type
? new Memo(federationRecord.memo_type as MemoType, federationRecord.memo)
: Memo.none()
if (userMemo.type !== "none" && federationMemo.type !== "none") {
throw new Error(
`Cannot set a custom memo. Federation record of ${formValues.destination} already specifies memo.`
)
}
const isMultisigTx = props.accountData.signers.length > 1
const payment = await createPaymentOperation({
asset: asset || Asset.native(),
amount: formValues.amount,
destination,
horizon
})