Esempio n. 1
0
    public void CreateCatIsContract()
    {
        var result = Create <Cat>(0, new object[] { CatCounter });

        UpdateLastCreatedCat(result.NewContractAddress);
        PersistentState.SetBool("IsContract", PersistentState.IsContract(result.NewContractAddress));
    }
Esempio n. 2
0
 public CreateWithAllParameters(ISmartContractState state,
                                char aChar,
                                Address anAddress,
                                bool aBool,
                                int anInt,
                                long aLong,
                                uint aUint,
                                ulong aUlong,
                                UInt128 aUInt128,
                                UInt256 aUInt256,
                                string aString,
                                byte[] bytes) : base(state)
 {
     PersistentState.SetChar("char", aChar);
     PersistentState.SetAddress("Address", anAddress);
     PersistentState.SetBool("bool", aBool);
     PersistentState.SetInt32("int", anInt);
     PersistentState.SetInt64("long", aLong);
     PersistentState.SetUInt32("uint", aUint);
     PersistentState.SetUInt64("ulong", aUlong);
     PersistentState.SetUInt128("UInt128", aUInt128);
     PersistentState.SetUInt256("UInt256", aUInt256);
     PersistentState.SetString("string", aString);
     PersistentState.SetBytes("bytes", bytes);
     this.Log(new Log
     {
         Char    = aChar,
         Address = anAddress,
         Bool    = aBool,
         Int     = anInt,
         Long    = aLong,
         Uint    = aUint,
         Ulong   = aUlong,
         UInt128 = aUInt128,
         UInt256 = aUInt256,
         String  = aString,
         Bytes   = bytes
     });
     Assert(PersistentState.GetChar("char") == aChar);
     Assert(PersistentState.GetAddress("Address") == anAddress);
     Assert(PersistentState.GetBool("bool") == aBool);
     Assert(PersistentState.GetInt32("int") == anInt);
     Assert(PersistentState.GetInt64("long") == aLong);
     Assert(PersistentState.GetUInt128("UInt128") == aUInt128);
     Assert(PersistentState.GetUInt256("UInt256") == aUInt256);
     Assert(PersistentState.GetString("string") == aString);
     byte[] bytesStored = PersistentState.GetBytes("bytes");
     Assert(bytesStored.Length == bytes.Length);
     for (int i = 0; i < bytes.Length; i++)
     {
         Assert(bytesStored[i] == bytes[i]);
     }
 }
Esempio n. 3
0
    private void UpdateAdminExecute(Address address, bool value)
    {
        PersistentState.SetBool($"{AdminKey}:{address}", value);

        Log(new RoleLog
        {
            Blame          = Message.Sender,
            UpdatedAddress = address,
            UpdatedValue   = value,
            Action         = nameof(UpdateAdmin),
            Block          = Block.Number
        });
    }
Esempio n. 4
0
    /// <summary>
    /// Updates the status of a contributor. Requires admin privileges.
    /// </summary>
    /// <param name="address">The address to update.</param>
    /// <param name="value">Status as boolean, true for approved contributor, false for not contributor.</param>
    public void UpdateContributor(Address address, bool value)
    {
        Assert(IsAdmin(Message.Sender));

        PersistentState.SetBool($"{ContributorKey}:{address}", value);

        Log(new RoleLog
        {
            Blame          = Message.Sender,
            UpdatedAddress = address,
            UpdatedValue   = value,
            Action         = nameof(UpdateContributor),
            Block          = Block.Number
        });
    }
Esempio n. 5
0
    public void Method()
    {
        // Create log that ultimately shouldn't be persisted due to failure.
        Log(new ArbitraryLog {
            Id = 1
        });

        // Create transfer that ultimately shouldn't be persisted due to failure.
        Transfer(new Address("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn"), 1);

        // Create storage that ultimately shouldn't be persisted due to failure.
        PersistentState.SetBool("Test", true);

        // Throws OutOfIndexException
        var array = new int[25];
        int value = array[26];
    }
Esempio n. 6
0
    public ExceptionInConstructor(ISmartContractState smartContractState) : base(smartContractState)
    {
        // Create log that ultimately shouldn't be persisted due to failure.
        Log(new ArbitraryLog {
            Id = 1
        });

        // Create transfer that ultimately shouldn't be persisted due to failure.
        Transfer(new Address("mipcBbFg9gMiCh81Kj8tqqdgoZub1ZJRfn"), 1);

        // Create storage that ultimately shouldn't be persisted due to failure.
        PersistentState.SetBool("Test", true);

        // Throw (unexpected) OutOfIndexException
        var array = new int[25];
        int value = array[26];
    }
Esempio n. 7
0
 private void AddPlayer(Address address)
 {
     PersistentState.SetAddress($"Player{PlayerCount}", address);
     PersistentState.SetBool($"Added:{address}", true);
     PlayerCount++;
 }