How to use the stellar-base.Hyper.fromString function in stellar-base

To help you get started, we’ve selected a few stellar-base 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 stellar / js-stellar-sdk / src / operation.js View on Github external
throw new Error("Must provide a destination for a payment operation");
        }
        if (!opts.destCurrency) {
            throw new Error("Must provide a destCurrency for a payment operation");
        }
        if (!opts.destAmount) {
            throw new Error("Must provide an destAmount for a payment operation");
        }


        let attributes = {};
        attributes.sendCurrency = opts.sendCurrency.toXdrObject();
        attributes.sendMax      = Hyper.fromString(String(opts.sendMax));
        attributes.destination  = Keypair.fromAddress(opts.destination).publicKey();
        attributes.destCurrency = opts.destCurrency.toXdrObject();
        attributes.destAmount       = Hyper.fromString(String(opts.destAmount));
        attributes.path         = opts.path ? opts.path : [];
        let payment = new xdr.PathPaymentOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.pathPayment(payment);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }
github stellar / js-stellar-sdk / src / operation.js View on Github external
static createAccount(opts) {
        if (!opts.destination) {
            throw new Error("Must provide a destination for a payment operation");
        }
        if (!opts.startingBalance) {
            throw new Error("Must provide a starting balance");
        }
        let attributes = {};
        attributes.destination  = Keypair.fromAddress(opts.destination).publicKey();
        attributes.startingBalance = Hyper.fromString(String(opts.startingBalance));
        let createAccount = new xdr.CreateAccountOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.createAccount(createAccount);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }
github stellar / js-stellar-sdk / src / operation.js View on Github external
static createOffer(opts) {
        let attributes = {};
        attributes.takerGets = opts.takerGets.toXdrObject();
        attributes.takerPays = opts.takerPays.toXdrObject();
        attributes.amount = Hyper.fromString(String(opts.amount));
        let approx = best_r(opts.price);
        attributes.price = new xdr.Price({
            n: approx[0],
            d: approx[1]
        });
        attributes.offerId = UnsignedHyper.fromString(String(opts.offerId));
        let createOfferOp = new xdr.CreateOfferOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.createOffer(createOfferOp);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }
github stellar / js-stellar-sdk / src / operation.js View on Github external
throw new Error("Must specify a send max");
        }
        if (!opts.destination) {
            throw new Error("Must provide a destination for a payment operation");
        }
        if (!opts.destCurrency) {
            throw new Error("Must provide a destCurrency for a payment operation");
        }
        if (!opts.destAmount) {
            throw new Error("Must provide an destAmount for a payment operation");
        }


        let attributes = {};
        attributes.sendCurrency = opts.sendCurrency.toXdrObject();
        attributes.sendMax      = Hyper.fromString(String(opts.sendMax));
        attributes.destination  = Keypair.fromAddress(opts.destination).publicKey();
        attributes.destCurrency = opts.destCurrency.toXdrObject();
        attributes.destAmount       = Hyper.fromString(String(opts.destAmount));
        attributes.path         = opts.path ? opts.path : [];
        let payment = new xdr.PathPaymentOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.pathPayment(payment);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }
github stellar / js-stellar-sdk / src / operation.js View on Github external
static payment(opts) {
        if (!opts.destination) {
            throw new Error("Must provide a destination for a payment operation");
        }
        if (!opts.currency) {
            throw new Error("Must provide a currency for a payment operation");
        }
        if (!opts.amount) {
            throw new Error("Must provide an amount for a payment operation");
        }

        let attributes = {};
        attributes.destination  = Keypair.fromAddress(opts.destination).publicKey();
        attributes.currency     = opts.currency.toXdrObject();
        attributes.amount       = Hyper.fromString(String(opts.amount));
        let payment = new xdr.PaymentOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.payment(payment);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }
github stellar / js-stellar-sdk / src / operation.js View on Github external
static changeTrust(opts) {
        let attributes      = {};
        attributes.line     = opts.currency.toXdrObject();
        let limit           = opts.limit ? limit : "9223372036854775807";
        attributes.limit    = Hyper.fromString(limit);
        if (opts.source) {
            attributes.source   = opts.source ? opts.source.masterKeypair : null;
        }
        let changeTrustOP = new xdr.ChangeTrustOp(attributes);

        let opAttributes = {};
        opAttributes.body = xdr.OperationBody.changeTrust(changeTrustOP);
        if (opts.source) {
            opAttributes.sourceAccount = Keypair.fromAddress(opts.source).publicKey();
        }
        let op = new xdr.Operation(opAttributes);
        return op;
    }