How to use the @iota/core.createPrepareTransfers function in @iota/core

To help you get started, we’ve selected a few @iota/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github IOTA-Ledger / blue-app-iota / tests / bundle-generator / index.js View on Github external
const fs = require("fs");
const { createPrepareTransfers, generateAddress } = require('@iota/core');
const { asTransactionObject } = require("@iota/transaction-converter");

const NUM_BUNDLES = 100;
const MAX_BUNDLE_SIZE = 10;

// prepare transfers offline
const prepareTransfers = createPrepareTransfers(undefined, Date.now());

function randomInt(min, max, excluding) {
  let value;
  do {
    value = Math.floor(Math.random() * (max - min + 1)) + min;
  } while (excluding.includes(value));

  return value;
}

function randomTrytes(length) {
  const possible = "NOPQRSTUVWXYZ9ABCDEFGHIJKLM";

  let text = "";
  for (let i = 0; i < length; i++) {
    text += possible.charAt(Math.floor(Math.random() * possible.length));
github iotaledger / iota.js / packages / account / src / preset.ts View on Github external
export function addressGeneration(this: any, addressGenerationParams: AddressGenerationParams) {
    const { seed, persistence, timeSource, network, now } = addressGenerationParams
    const prepareTransfers = createPrepareTransfers(undefined, now)
    const emitter = this // tslint:disable-line

    function generateCDA(cdaParams: CDAParams): Promise {
        if (!cdaParams) {
            throw new Error(
                'Provide an object with conditions for the CDA: { timeoutAt, [multiUse], [exeptectedAmount], [security=2] }'
            )
        }

        const { timeoutAt, expectedAmount, multiUse } = cdaParams

        return Promise.try(() => timeSource().then(currentTime => verifyCDAParams(currentTime, cdaParams)))
            .then(persistence.increment)
            .then(index => {
                const security = cdaParams.security || addressGenerationParams.security
                const address = signingAddress(digests(key(subseed(seed, tritsToValue(index)), security)))
github iotaledger / industry-marketplace / ServiceApp / server / src / utils / walletHelper.ts View on Github external
const transferFunds = async (wallet, totalAmount, transfers) => {
    try {
        const { address, keyIndex, seed } = wallet;
        const { sendTrytes, getLatestInclusion } = composeAPI({ provider });
        const prepareTransfers = createPrepareTransfers();
        const balance = await getBalance(address);

        if (balance === 0) {
            console.error('transferFunds. Insufficient balance', address);
            return null;
        }
        if (balance < totalAmount) {
            throw new Error(`Insufficient balance: ${balance}. Needed: ${totalAmount}`);
        }

        return new Promise((resolve, reject) => {
            const remainderAddress = generateAddress(seed, keyIndex + 1);
            const options = {
                inputs: [{
                    address,
                    keyIndex,
github iotaledger / iota.js / packages / account / src / preset.ts View on Github external
export function transactionIssuance(
    this: any,
    { seed, deposits, persistence, network, timeSource, now }: TransactionIssuanceParams
) {
    const { getBalance, wereAddressesSpentFrom } = network
    const prepareTransfers = createPrepareTransfers(undefined, now)
    const noChecksum = (address: string) => address.slice(0, -(CDA_CHECKSUM_LENGTH / TRYTE_WIDTH))

    const transactionIssuer = {
        sendToCDA: (cdaTransfer: CDATransfer): Promise> => {
            if (!cdaTransfer) {
                throw new Error(
                    'Provide an object with conditions and value for the CDA transfer: { timeoutAt, [multiUse], [exeptectedAmount], [security=2], value }'
                )
            }

            return (cdaTransfer.multiUse === true
                ? Promise.resolve()
                : persistence
                      .get([SENT_TO_ADDRESS_PREFIX, noChecksum(cdaTransfer.address)].join(':'))
                      .then(() => {
                          throw new Error(