Exemplo n.º 1
0
 public static byte[] GetStorge(StorageContext context, byte[] key)
 {
     return(Storage.Get(context, key));
 }
Exemplo n.º 2
0
 protected internal void PutEx(StorageContext context, byte[] key, byte[] value, StorageFlags flags)
 {
     PutExInternal(context, key, value, flags);
 }
Exemplo n.º 3
0
 public static void PutStorge(StorageContext context, byte[] key, byte[] value)
 {
     Storage.Put("context", key, value);
 }
Exemplo n.º 4
0
 protected internal void Put(StorageContext context, byte[] key, byte[] value)
 {
     PutExInternal(context, key, value, StorageFlags.None);
 }
Exemplo n.º 5
0
 public static void DeleteStorge(StorageContext context, byte[] key)
 {
     Storage.Delete(context, key);
 }
Exemplo n.º 6
0
 public static object Main(string operation, params object[] args)
 {
     if (operation == "GetHeight")
     {
         return(GetHeight());
     }
     else if (operation == "GetHeader")
     {
         return(GetHeader(args[0]));
     }
     else if (operation == "GetBlock")
     {
         return(GetBlock(args[0]));
     }
     else if (operation == "GetTransaction")
     {
         return(GetTransaction(args[0]));
     }
     else if (operation == "GetContract")
     {
         return(GetContract(args[0]));
     }
     else if (operation == "GetHeaderHash")
     {
         return(GetHeaderHash(args[0]));
     }
     else if (operation == "GetHeaderVersion")
     {
         return(GetHeaderVersion(args[0]));
     }
     else if (operation == "GetHeaderPrevHash")
     {
         return(GetHeaderPrevHash(args[0]));
     }
     else if (operation == "GetHeaderIndex")
     {
         return(GetHeaderIndex(args[0]));
     }
     else if (operation == "GetHeaderMerkleRoot")
     {
         return(GetHeaderMerkleRoot(args[0]));
     }
     else if (operation == "GetHeaderTimestamp")
     {
         return(GetHeaderTimestamp(args[0]));
     }
     else if (operation == "GetHeaderConsensusData")
     {
         return(GetHeaderConsensusData(args[0]));
     }
     else if (operation == "GetHeaderNextConsensus")
     {
         return(GetHeaderNextConsensus(args[0]));
     }
     else if (operation == "GetBlockTransactionCount")
     {
         return(GetBlockTransactionCount(args[0]));
     }
     else if (operation == "GetBlockTransactions")
     {
         return(GetBlockTransactions(args[0]));
     }
     else if (operation == "GetBlockTransaction_40")
     {
         return(GetBlockTransaction_40(args[0], args[1]));
     }
     else if (operation == "GetBlockTransaction_44")
     {
         return(GetBlockTransaction_44(args[0]));
     }
     else if (operation == "GetBlockTransaction_45")
     {
         return(GetBlockTransaction_45(args[0]));
     }
     else if (operation == "GetContract_Create")
     {
         return(GetContract_Create((byte[])args[0], (bool)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5], (string)args[6]));
     }
     else if (operation == "GetContract_Destroy")
     {
         return(GetContract_Destroy());
     }
     else if (operation == "GetContract_Migrate")
     {
         return(GetContract_Migrate((byte[])args[0], (bool)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5], (string)args[6]));
     }
     else if (operation == "GetContract_Script")
     {
         return(GetContract_Script((byte[])args[0]));
     }
     else if (operation == "GetStorageContext")
     {
         return(GetStorageContext(args));
     }
     else if (operation == "GetContract_StorageContext")
     {
         return(GetContract_StorageContext((byte[])args[0]));
     }
     else if (operation == "GetTransaction_Attribute")
     {
         return(GetTransaction_Attribute((byte[])args[0]));
     }
     else if (operation == "GetTransaction_Hash")
     {
         return(GetTransaction_Hash((byte[])args[0]));
     }
     else if (operation == "GetTransaction_Type")
     {
         return(GetTransaction_Type((byte[])args[0]));
     }
     else if (operation == "GetTransactionAttribute_Data")
     {
         return(GetTransactionAttribute_Data((byte[])args[0], (int)args[1]));
     }
     else if (operation == "GetTransactionAttribute_Usage")
     {
         return(GetTransactionAttribute_Usage((byte[])args[0], (int)args[1]));
     }
     else if (operation == "GetTransaction_Attributes")
     {
         return(GetTransaction_Attributes((byte[])args[0]));
     }
     else if (operation == "GetCallingScriptHash")
     {
         return(GetCallingScriptHash());
     }
     else if (operation == "GetEntryScriptHash")
     {
         return(GetEntryScriptHash());
     }
     else if (operation == "GetExecutingScriptHash")
     {
         return(GetExecutingScriptHash());
     }
     else if (operation == "GetScriptContainer")
     {
         return(GetScriptContainer());
     }
     else if (operation == "CheckWitness")
     {
         return(GetCheckWitness((byte[])args[0]));
     }
     else if (operation == "Log_134")
     {
         Log_134();
         return(true);
     }
     else if (operation == "Log_134")
     {
         Log_134();
         return(true);
     }
     else if (operation == "Log_135")
     {
         Log_135();
         return(true);
     }
     else if (operation == "Log_136")
     {
         Log_136(args);
         return(true);
     }
     else if (operation == "Log_137")
     {
         Log_137();
         return(true);
     }
     else if (operation == "Log_138")
     {
         Log_138();
         return(true);
     }
     else if (operation == "Notify_130")
     {
         Notify_130();
         return(true);
     }
     else if (operation == "Notify_131")
     {
         Notify_131();
         return(true);
     }
     else if (operation == "Notify_132")
     {
         Notify_132();
         return(true);
     }
     else if (operation == "Notify_133")
     {
         Notify_133();
         return(true);
     }
     else if (operation == "GetTime")
     {
         return(GetTime());
     }
     else if (operation == "GetCurrentContext")
     {
         return(GetCurrentContext());
     }
     else if (operation == "Delete_114")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         DeleteStorge(Storage.CurrentContext, key);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Delete_120")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         // PutStorge(Storage.CurrentContext, key, value);
         DeleteStorge(Storage.CurrentContext, key);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Delete_115")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         DeleteStorge(Storage.CurrentContext, key);
         DeleteStorge(Storage.CurrentContext, key);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Delete_116")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         DeleteStorge(null, key);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Get_92")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Get_93")
     {
         byte[] key_1 = (byte[])args[0];
         byte[] value = (byte[])args[1];
         byte[] key_2 = (byte[])args[2];
         // PutStorge(Storage.CurrentContext, key_1, value);
         return(GetStorge(Storage.CurrentContext, key_2));
     }
     else if (operation == "Get_94")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         return(GetStorge(null, key));
     }
     else if (operation == "Get_98")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         DeleteStorge(Storage.CurrentContext, key);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Put_99")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Put_100")
     {
         byte[]         key   = (byte[])args[0];
         byte[]         value = (byte[])args[1];
         StorageContext _c    = (StorageContext)args[1];
         PutStorge(_c, key, value);
         return(GetStorge(_c, key));
     }
     else if (operation == "Put_101")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(null, key, value);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Put_107")
     {
         byte[] key     = (byte[])args[0];
         byte[] value_1 = (byte[])args[1];
         byte[] value_2 = (byte[])args[2];
         PutStorge(Storage.CurrentContext, key, value_1);
         PutStorge(Storage.CurrentContext, key, value_2);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else if (operation == "Put_108_1")
     {
         byte[] key   = (byte[])args[0];
         byte[] value = (byte[])args[1];
         PutStorge(Storage.CurrentContext, key, value);
         return(GetStorge(Storage.CurrentContext, key));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Vote for a proposal
        /// </summary>
        /// <param name="args">list of arguments [PROPOSAL_ID, VOTE]</param>
        /// <returns>result of the execution</returns>
        static bool Vote(object[] args)
        {
            if (args.Length != 2)
            {
                return(false);
            }

            // get proposal from storage
            byte[] proposal_id = (byte[])args[0];
            int    vote        = (int)args[1];

            // Extract caller
            Transaction tx = (Transaction)ExecutionEngine.ScriptContainer;

            TransactionOutput[] inputs    = tx.GetReferences();
            TransactionOutput   reference = inputs[0];

            byte[] caller = reference.ScriptHash;

            StorageContext ctx = Storage.CurrentContext;

            byte[] proposal_storage = Storage.Get(ctx, proposal_id);

            // check proposal existence
            if (proposal_storage.Length == 0)
            {
                Runtime.Log("Proposal not found");
                return(false);
            }

            // check if address already voted
            byte[] key = proposal_id.Concat(caller);
            if (Storage.Get(ctx, key).Length > 0)
            {
                Runtime.Log("Already voted");
                return(false);
            }

            // Deserialize proposal array
            object[] proposal = (object[])proposal_storage.Deserialize();

            // check if tx is right signed
            if (!Runtime.CheckWitness(caller))
            {
                Runtime.Log("You are not who you say");
                return(false);
            }

            // iterate authorized address
            int  index      = 0;
            bool authorized = false;

            while (index < ((string[])proposal[3]).Length)
            {
                // for address in proposal[3]:
                if ((object)((string[])proposal[3])[index] == caller)
                {
                    authorized = true;
                    break;
                }
                index += 1;
            }
            if (!authorized)
            {
                Runtime.Log("Not allowed to vote");
                return(false);
            }

            // increment vote counter
            if (vote == 1)
            {
                Runtime.Log("Yes!");
                proposal[1] = (int)proposal[1] + 1;
            }
            else
            {
                Runtime.Log("No!");
                proposal[2] = (int)proposal[2] + 1;
            }

            // serialize proposal and write to storage
            proposal_storage = proposal.Serialize();
            Storage.Put(ctx, proposal_id, proposal_storage);

            // mark address as voted
            Storage.Put(ctx, key, 1);
            return(true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Vote for a proposal
        /// </summary>
        /// <param name="args">list of arguments [PROPOSAL_ID, VOTER ADDR, VOTE]</param>
        /// <returns>result of the execution</returns>
        static bool Vote(object[] args)
        {
            if (args.Length != 3)
            {
                return(false);
            }

            // get proposal from storage
            string         proposal_id = (string)args[0];
            StorageContext ctx         = Storage.CurrentContext;

            byte[] proposal_storage = Storage.Get(ctx, proposal_id);

            // check proposal existence
            if (proposal_storage.Length == 0)
            {
                Runtime.Log("Proposal not found");
                return(false);
            }

            // check if address already voted
            string key = proposal_id + (string)args[1];

            if (Storage.Get(ctx, key).Length > 0)
            {
                Runtime.Log("Already voted");
                return(false);
            }

            // Deserialize proposal array
            object[] proposal = (object[])proposal_storage.Deserialize();

            // check if tx is right signed
            if (!Runtime.CheckWitness((byte[])args[1]))
            {
                Runtime.Log("You are not who you say");
                return(false);
            }

            // iterate authorized address
            int  index      = 0;
            bool authorized = false;

            while (index < ((string[])proposal[3]).Length)
            {
                // for address in proposal[3]:
                if ((object)((string[])proposal[3])[index] == args[1])
                {
                    authorized = true;
                    break;
                }
                index += 1;
            }
            if (!authorized)
            {
                Runtime.Log("Not allowed to vote");
                return(false);
            }

            // increment vote counter
            if ((int)args[2] == 1)
            {
                Runtime.Log("Yes!");
                proposal[1] = (int)proposal[1] + 1;
            }
            else
            {
                Runtime.Log("No!");
                proposal[2] = (int)proposal[2] + 1;
            }

            // serialize proposal and write to storage
            proposal_storage = proposal.Serialize();
            Storage.Put(ctx, proposal_id, proposal_storage);

            // mark address as voted
            Storage.Put(ctx, key, 1);
            return(true);
        }