示例#1
0
        public static NebAccount FromAddress(string address)
        {
            var acc = new NebAccount();

            if (!IsValidAddress(address, AddressType.Normal))
            {
                throw new ArgumentException("Invalid Account Address");
            }

            acc.m_address = Base58.Decode(address);
            return(acc);
        }
示例#2
0
        public NebTransaction(uint chainId, NebAccount fromAccount, NebAccount toAccount, string value, ulong nonce,
                              string gasPrice, string gasLimit, NebContract contract = null)
        {
            m_chainId     = chainId;
            m_fromAccount = fromAccount;
            m_toAccount   = toAccount;
            m_value       = BigInteger.Parse(value);
            m_nonce       = nonce;
#if DEBUG
            m_timestamp = 0;
#else
            m_timestamp = GetTimeStamp(DateTime.Now);
#endif
            m_gasPrice = BigInteger.Parse(gasPrice);
            m_gasLimit = BigInteger.Parse(gasLimit);
            m_contract = contract ?? NebContract.DefaultContract;

            if (m_gasPrice <= 0)
            {
                m_gasPrice = new BigInteger(1000000);
            }

            if (m_gasLimit <= 0)
            {
                m_gasLimit = new BigInteger(20000);
            }

            m_data = new Corepb.Data();

            switch (m_contract.Content)
            {
            case NebContract.BinaryContent _:
                m_data.Type    = "binary";
                m_data.Payload = ByteString.CopyFrom(((NebContract.BinaryContent)m_contract.Content).Data);
                break;

            case NebContract.DeployContent _:
                m_data.Type    = "deploy";
                m_data.Payload =
                    ByteString.CopyFromUtf8(JsonConvert.SerializeObject(m_contract.Content, JsonSettings));
                break;

            case NebContract.CallContent _:
                m_data.Type    = "call";
                m_data.Payload =
                    ByteString.CopyFromUtf8(JsonConvert.SerializeObject(m_contract.Content, JsonSettings));
                break;

            default:
                throw new Exception();
            }
        }