Exemple #1
0
        public ExecutionStatus GetDeployHeight(UInt160 contractAddress, SystemContractExecutionFrame frame)
        {
            frame.ReturnValue = new byte[64];
            try
            {
                if (HardforkHeights.IsHardfork_3Active(frame.InvocationContext.Snapshot.Blocks.GetTotalBlockHeight()))
                {
                    if (HardforkHeights.IsHardfork_6Active(
                            frame.InvocationContext.Snapshot.Blocks.GetTotalBlockHeight()))
                    {
                        frame.ReturnValue = _deployHeight.GetValue(contractAddress.ToBytes()) ?? new byte[64];
                    }
                    else
                    {
                        frame.ReturnValue = _deployHeight.GetValue(contractAddress.ToBytes());
                    }
                }
            }
            catch (Exception e)
            {
                Logger.LogInformation($"Exception while get deploy height: {e}");
            }

            return(ExecutionStatus.Ok);
        }
Exemple #2
0
        public static UInt256 ToUInt256(this UInt160 value)
        {
            var buffer = new byte[32];

            Array.Copy(value.ToBytes(), 0, buffer, 12, 20);
            return(buffer.ToUInt256());
        }
Exemple #3
0
 private static string PrettyParam(dynamic param)
 {
     return(param switch
     {
         UInt256 x => x.ToBytes().ToHex(),
         UInt160 x => x.ToBytes().ToHex(),
         byte[] b => b.ToHex(),
         byte[][] s => string.Join(", ", s.Select(t => t.ToHex())),
         _ => param.ToString()
     });
Exemple #4
0
        public ExecutionStatus SetDeployHeight(UInt160 contractAddress, byte[] height, SystemContractExecutionFrame frame)
        {
            try
            {
                // Only contract itself can change its deploy height
                if (!frame.CurrentAddress.Equals(contractAddress))
                {
                    throw new Exception("Only contract itself can change its deploy height");
                }

                if (HardforkHeights.IsHardfork_3Active(frame.InvocationContext.Snapshot.Blocks.GetTotalBlockHeight()))
                {
                    _deployHeight.SetValue(contractAddress.ToBytes(), height.ToArray());
                }
            }
            catch (Exception e)
            {
                Logger.LogInformation($"Exception while set deploy height: {e}");
                return(ExecutionStatus.UnknownError);
            }

            return(ExecutionStatus.Ok);
        }
 public static byte[] BuildPrefix(this EntryPrefix prefix, UInt160 key)
 {
     return(BuildPrefix(prefix, key.ToBytes()));
 }
Exemple #6
0
 public static string ToHex(this UInt160 value, bool prefix = true)
 {
     return(value.ToBytes().ToHex(prefix));
 }
Exemple #7
0
 public static BigInteger ToBigInteger(this UInt160 value)
 {
     return(new BigInteger(value.ToBytes().Reverse().Concat(new byte[] { 0 }).ToArray()));
 }
Exemple #8
0
        public void SetMinter(UInt160 value)
        {
            var key = EntryPrefix.MinterAddress.BuildPrefix();

            _state.AddOrUpdate(key, value.ToBytes());
        }
 private void SetAllowance(UInt160 owner, UInt160 spender, UInt256 amount)
 {
     _allowance.SetValue(owner.ToBytes().Concat(spender.ToBytes()), amount.ToBytes());
 }
        private UInt256 GetAllowance(UInt160 owner, UInt160 spender)
        {
            var amountBytes = _allowance.GetValue(owner.ToBytes().Concat(spender.ToBytes()));

            return(amountBytes.Length == 0 ? UInt256Utils.Zero : amountBytes.ToUInt256());
        }