How to use the @cityofzion/neon-core/lib/u.Fixed8 function in @cityofzion/neon-core

To help you get started, we’ve selected a few @cityofzion/neon-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 NeoNextClub / neoline / src / app / popup / notification / invoke / invoke.component.ts View on Github external
this.getBalance(this.neon.address, assetid).subscribe((balances: any) => {
                if (balances.length === 0) {
                    reject('no balance');
                }
                let assetId = balances[0].asset_id;
                if (assetId.startsWith('0x') && assetId.length === 66) {
                    assetId = assetId.substring(2);
                }
                newTx.addOutput({ assetId, value: new Fixed8(amount), scriptHash: toScript });
                let curr = 0.0;
                for (const item of balances) {
                    curr += parseFloat(item.value) || 0;
                    newTx.inputs.push(new TransactionInput({
                        prevIndex: item.n, prevHash: item.txid.startsWith('0x') && item.txid.length == 66 ? item.txid.substring(2) : item.txid
                    }));
                    if (curr >= amount + fee) {
                        break;
                    }
                }
                const payback = (assetId === GAS || assetId === GAS.substring(2)) ?
                    this.global.mathSub(this.global.mathSub(curr, amount), fee) : this.global.mathSub(curr, amount);
                if (payback < 0) {
                    reject('no enough balance to pay');
                }
                if (payback > 0) {
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
const fromScript = wallet.getScriptHashFromAddress(from);
        const toScript = wallet.getScriptHashFromAddress(to);
        if (fromScript.length !== 40 || toScript.length !== 40) {
            throw new Error('target address error');
        }
        if (balances.length === 0) {
            throw new Error('no balance');
        }
        let assetId = balances[0].asset_id;
        if (assetId.startsWith('0x') && assetId.length === 66) {
            assetId = assetId.substring(2);
        }
        const newTx = new tx.ContractTransaction();

        newTx.addOutput({ assetId, value: new Fixed8(amount), scriptHash: toScript });
        let curr = 0.0;
        for (const item of balances) {
            curr += parseFloat(item.value) || 0;
            newTx.inputs.push(new TransactionInput({
                prevIndex: item.n, prevHash: item.txid.startsWith('0x') &&
                    item.txid.length === 66 ? item.txid.substring(2) : item.txid
            }));
            if (curr >= amount + fee) {
                break;
            }
        }
        const payback = (assetId === GAS || assetId === GAS.substring(2)) ?
            this.global.mathSub(this.global.mathSub(curr, amount), fee) : this.global.mathSub(curr, amount);
        if (payback < 0) {
            throw new Error('no enough balance to pay');
        }
github NeoNextClub / neoline / src / app / popup / notification / invoke / invoke.component.ts View on Github external
for (const item of balances) {
                    curr += parseFloat(item.value) || 0;
                    newTx.inputs.push(new TransactionInput({
                        prevIndex: item.n, prevHash: item.txid.startsWith('0x') && item.txid.length == 66 ? item.txid.substring(2) : item.txid
                    }));
                    if (curr >= amount + fee) {
                        break;
                    }
                }
                const payback = (assetId === GAS || assetId === GAS.substring(2)) ?
                    this.global.mathSub(this.global.mathSub(curr, amount), fee) : this.global.mathSub(curr, amount);
                if (payback < 0) {
                    reject('no enough balance to pay');
                }
                if (payback > 0) {
                    newTx.addOutput({ assetId, value: new Fixed8(payback), scriptHash: fromScript });
                }
                resolve(newTx);
            });
        });
github NeoNextClub / neoline / src / app / core / services / neon.service.ts View on Github external
curr += parseFloat(item.value) || 0;
            newTx.inputs.push(new TransactionInput({
                prevIndex: item.n, prevHash: item.txid.startsWith('0x') &&
                    item.txid.length === 66 ? item.txid.substring(2) : item.txid
            }));
            if (curr >= amount + fee) {
                break;
            }
        }
        const payback = (assetId === GAS || assetId === GAS.substring(2)) ?
            this.global.mathSub(this.global.mathSub(curr, amount), fee) : this.global.mathSub(curr, amount);
        if (payback < 0) {
            throw new Error('no enough balance to pay');
        }
        if (payback > 0) {
            newTx.addOutput({ assetId, value: new Fixed8(payback), scriptHash: fromScript });
        }
        return newTx;
    }
    public createTxForNEP5(from: string, to: string, scriptHash: string, amount: number, decimals: number): Transaction {
github NeoNextClub / neoline / src / app / popup / notification / deploy / deploy.component.ts View on Github external
} catch (error) {
                reject(error);
            }
            try {
                newTx = await this.addFee(fromAddress, newTx, amount + parseFloat(this.pramsData.networkFee));
            } catch (error) {
                this.chrome.windowCallback({
                    error: ERRORS.INSUFFICIENT_FUNDS,
                    return: requestTarget.Deploy,
                    ID: this.messageID
                });
                window.close();
            }
            const uniqTag = `from NEOLine at ${new Date().getTime()}`;
            newTx.addAttribute(tx.TxAttrUsage.Remark1, u.reverseHex(u.str2hexstring(uniqTag)));
            newTx.gas = new Fixed8(amount);
            resolve(newTx);
        });
    }