Exemplo n.º 1
0
        public static bool SetOracleOutcome(byte[] txHash, byte[] result)
        {
            //TODO: check witness
            if (!Runtime.CheckWitness(admin))
            {
                Runtime.Notify("Checkwitness failed.");
                return(false);
            }

            Storage.Put(Storage.CurrentContext, txHash, result);

            //remove txHash from undoRequest map
            Map <byte[], string> undoRequest = new Map <byte[], string>();

            byte[] v = Storage.Get(Storage.CurrentContext, "UndoRequest");
            if (v.Length != 0)
            {
                undoRequest = (Map <byte[], string>)Helper.Deserialize(v);
            }
            undoRequest.Remove(txHash);

            byte[] b = Helper.Serialize(undoRequest);
            Storage.Put(Storage.CurrentContext, "UndoRequest", b);
            Runtime.Notify("SetOracleOutcome Done");
            return(true);
        }
Exemplo n.º 2
0
    public static void Main()
    {
        // create struct instance
        Person p = new Person();

        p.Name = "bob";
        p.Age  = 20;
        Runtime.Notify(p.Name);
        Runtime.Notify(p.Age);

        // serialize struct instance to byte[]
        byte[] b = Helper.Serialize(p);

        // deserialize byte[] to struct
        Person p2 = (Person)Helper.Deserialize(b);

        Runtime.Notify(p2.Name);
        Runtime.Notify(p2.Age);

        // create struct array
        Person[] array = new Person[] { new Person {
                                            Name = "tom", Age = 18
                                        }, new Person {
                                            Name = "jack", Age = 20
                                        } };
    }
Exemplo n.º 3
0
        public static bool CreateOracleRequest(string request, byte[] address)
        {
            //TODO: check request format

            //TODO: transfer ong

            Transaction tx = (Transaction)ExecutionEngine.ScriptContainer;

            byte[] txHash = tx.Hash;
            //Runtime.Notify("txHash is :", txHash);

            Map <byte[], string> undoRequest = new Map <byte[], string>();

            byte[] v = Storage.Get(Storage.CurrentContext, "UndoRequest");
            if (v.Length != 0)
            {
                undoRequest = (Map <byte[], string>)Helper.Deserialize(v);
            }
            undoRequest[txHash] = request;

            byte[] b = Helper.Serialize(undoRequest);
            Storage.Put(Storage.CurrentContext, "UndoRequest", b);
            Runtime.Notify("CreateOracleRequest Done");
            return(true);
        }
Exemplo n.º 4
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.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);
    }
Exemplo n.º 5
0
        public static bool Revoke(byte[] claimId, byte[] ontId)
        {
            byte[] v = Storage.Get(Storage.CurrentContext, claimId);

            if (v == null)
            {
                ErrorEvent(claimId, " not existed!");
                return(false);
            }

            ClaimTx c = (ClaimTx)Helper.Deserialize(v);

            if (c.status != 1)
            {
                ErrorEvent(claimId, " invalid status.");
                return(false);
            }
            if (!EqualBytes(c.commiterId, ontId))
            {
                ErrorEvent(ontId, " invalid.");
                return(false);
            }

            c.status = 0;

            byte[] tx = Helper.Serialize(c);
            Storage.Put(Storage.CurrentContext, claimId, tx);

            PushEvent(ontId, " revoke claim: ", claimId);
            return(true);
        }
Exemplo n.º 6
0
    public static void Main()
    {
        Map <string, int> m = new Map <string, int>();

        m["k1"] = 100;
        m["k2"] = 200;
        Runtime.Notify(m["k1"]);
        Runtime.Notify(m["k2"]);

        // seriallize
        byte[] b = Helper.Serialize(m);
        Storage.Put(Storage.CurrentContext, "mapexample", b);
        byte[] v = Storage.Get(Storage.CurrentContext, "mapexample");

        // deserialize
        Map <string, int> m2 = (Map <string, int>)Helper.Deserialize(v);

        Runtime.Notify(m2["k1"]);
        Runtime.Notify(m2["k2"]);
    }
Exemplo n.º 7
0
        // claimId 文件哈希
        // commiterId 具体描述
        // ownerId ontid
        public static bool Commit(byte[] claimId, byte[] commiterId, byte[] ownerId)
        {
            byte[] v = Storage.Get(Storage.CurrentContext, claimId);

            if (v != null)
            {
                ErrorEvent(claimId, " existed!");
                return(false);
            }

            ClaimTx c = new ClaimTx();

            c.claimId    = claimId;
            c.status     = 1;
            c.commiterId = commiterId;
            c.ownerId    = ownerId;

            byte[] tx = Helper.Serialize(c);

            Storage.Put(Storage.CurrentContext, claimId, tx);
            PushEvent(commiterId, " create new claim: ", claimId);
            return(true);
        }