Example #1
0
    public static bool IssueBond(string bondName, uint parValue, uint purchaseEndTime, uint interval, uint round, uint couponRate, ulong totalCap, byte[] Account)
    {
        if (!Runtime.CheckWitness(admin))
        {
            return(false);
        }
        if (purchaseEndTime <= Runtime.Time)
        {
            return(false);
        }
        if (totalCap < minIssueCap || round < minRound || couponRate <= 0 || interval < minInterval)
        {
            return(false);
        }
        if (!validateAddress(Account))
        {
            return(false);
        }

        BondItem bond = new BondItem();

        bond.ParValue        = parValue;
        bond.purchaseEndTime = purchaseEndTime;
        bond.CouponRate      = couponRate;
        bond.Interval        = interval;
        bond.TotalCap        = totalCap;
        bond.remainCap       = totalCap;
        bond.Round           = round;
        bond.Maturity        = purchaseEndTime + round * interval;

        byte[] b = Helper.Serialize(bond);
        Storage.Put(Storage.CurrentContext, bondPrefix.Concat(bondName.AsByteArray()), b);

        return(true);
    }
Example #2
0
    public static bool PayInterstOrPrincipal(string bondName, byte[] account)
    {
        if (!validateBond(bondName))
        {
            return(false);
        }

        byte[]     investorKey = bondInvestorPrefix.Concat(bondName.AsByteArray()).Concat(account);
        BigInteger balance     = Storage.Get(Storage.CurrentContext, investorKey).AsBigInteger();

        if (balance < minInvestCap)
        {
            return(false);
        }

        BondItem bond = (BondItem)Helper.Deserialize(GetBond(bondName));

        byte[]     paidKey      = bondPaidPrefix.Concat(bondName.AsByteArray()).Concat(account);
        BigInteger paidRound    = Storage.Get(Storage.CurrentContext, paidKey).AsBigInteger();
        BigInteger currentRound = (Runtime.Time - bond.purchaseEndTime) / bond.Interval;

        if (paidRound > bond.Round)
        {
            return(false);
        }
        if (currentRound > bond.Round)
        {
            currentRound = bond.Round;
        }

        BigInteger investValue = Storage.Get(Storage.CurrentContext, investorKey).AsBigInteger();
        BigInteger interst     = (currentRound - paidRound) * (investValue * bond.CouponRate / 100);

        byte[] ret;
        if (currentRound == bond.Round)
        {
            ret = Native.Invoke(0, ontAddr, "transfer", new object[1] {
                new Transfer {
                    From = bond.Account, To = account, Value = (ulong)(interst + investValue)
                }
            });
        }
        else
        {
            ret = Native.Invoke(0, ontAddr, "transfer", new object[1] {
                new Transfer {
                    From = bond.Account, To = account, Value = (ulong)interst
                }
            });
        }

        if (ret[0] != 1)
        {
            return(false);
        }
        Storage.Put(Storage.CurrentContext, paidKey, paidRound + 1);

        return(true);
    }
Example #3
0
    public static bool InvestBond(string bondName, byte[] account, uint bondNumber)
    {
        if (!Runtime.CheckWitness(account))
        {
            return(false);
        }
        if (bondNumber <= 0 || !validateAddress(account) || !validateBond(bondName))
        {
            return(false);
        }
        BondItem bond = (BondItem)Helper.Deserialize(GetBond(bondName));

        if (Runtime.Time > bond.purchaseEndTime)
        {
            Runtime.Notify("bond subscription has been ended.");
            return(false);
        }

        uint investValue = bondNumber * bond.ParValue;

        if (bond.remainCap < investValue)
        {
            Runtime.Notify("bond remain invest capacity not enough.");
            return(false);
        }

        byte[] ret = Native.Invoke(0, ontAddr, "transfer", new object[1] {
            new Transfer {
                From = account, To = bond.Account, Value = investValue
            }
        });
        if (ret[0] != 1)
        {
            return(false);
        }
        bond.remainCap = bond.TotalCap - investValue;

        byte[]     investorKey = bondInvestorPrefix.Concat(bondName.AsByteArray()).Concat(account);
        BigInteger balance     = Storage.Get(Storage.CurrentContext, investorKey).AsBigInteger();

        Storage.Put(Storage.CurrentContext, investorKey, balance + investValue);

        return(true);
    }
        public List <BondItem> getListBonds()
        {
            bus_Bond             bus       = new bus_Bond();
            List <BondItem>      bondsList = new List <BondItem>();
            List <V_BOND_STATIC> bondsAll  = bus.GetListAllBondStatic(16);

            foreach (V_BOND_STATIC item in bondsAll)
            {
                BondItem bond = new BondItem();
                bond.Bond      = item.BOND_CODE;
                bond.Termmin   = "1";
                bond.Termmax   = "10";
                bond.Couponmin = "5.5";
                bond.Couponmax = "10.5";
                bond.Amount    = "5000000000";
                bond.Category  = "O";
                bondsList.Add(bond);
            }
            return(bondsList);
        }