Esempio n. 1
0
        /// <summary>
        /// return balance of NFT in batch address
        /// execute the return value with eth_call
        /// </summary>
        /// <param name="_transactionNonce"></param>
        /// <param name="_chainId"></param>
        /// <param name="_addr"></param>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static string BalanceOf(Address _addr, uint _id)
        {
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_BALANCEOF);

            _abi.Add(_addr);
            _abi.Add(_id);
            return(_abi.ToString());
        }
Esempio n. 2
0
        public static string Burn(uint _transactionNonce, uint _chainId, Address _addrFrom, string _contractAddress, uint _nftId, uint _amount)
        {
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_BURN);

            _abi.Add(_addrFrom);
            _abi.Add(_nftId);
            _abi.Add(_amount);
            return(BuildSendDataTransaction(_transactionNonce, _chainId, _addrFrom.Private, _contractAddress, _abi.ToData()));
        }
Esempio n. 3
0
        public static string SafeBatchTransferFrom(uint _transactionNonce, uint _chainId, Address _addrFrom, Address _addrTo, string _contractAddress, Array _ids, Array _amounts, string _hexData)
        {
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_SAFEBATCHTRANSFERFROM);

            _abi.Add(_addrFrom);
            _abi.Add(_addrTo);
            _abi.Add(_ids);
            _abi.Add(_amounts);
            _abi.Add(new Number(_hexData));
            return(BuildSendDataTransaction(_transactionNonce, _chainId, _addrFrom.Private, _contractAddress, _abi.ToData()));
        }
Esempio n. 4
0
        /// <summary>
        /// return balance of NFT in address
        /// addrs.length=_ids.length
        /// execute the return value with eth_call
        /// </summary>
        /// <param name="_transactionNonce"></param>
        /// <param name="_chainId"></param>
        /// <param name="_addr"></param>
        /// <param name="_id"></param>
        /// <returns></returns>
        public static string BalanceOfBatch(Array _addrs, Array _ids)
        {
            if (_addrs.Length != _ids.Length)
            {
                throw new ArgumentException("Address length not equal ids length");
            }
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_BALANCEOFBATCH);

            _abi.Add(_addrs);
            _abi.Add(_ids);
            return(_abi.ToString());
        }
Esempio n. 5
0
        public static string BurnBatch(uint _transactionNonce, uint _chainId, Address _addrFrom, string _contractAddress, Array _nftIds, Array _amounts)
        {
            if (_nftIds.Length != _amounts.Length)
            {
                throw new ArgumentException("NFT ids length not equal amounts length");
            }
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_BURNBATCH);

            _abi.Add(_addrFrom);
            _abi.Add(_nftIds);
            _abi.Add(_amounts);
            return(BuildSendDataTransaction(_transactionNonce, _chainId, _addrFrom.Private, _contractAddress, _abi.ToData()));
        }
Esempio n. 6
0
        public static string Transfer()
        {
            ContractABI _abi = new ContractABI(Ethereum.EIP1155_METHOD_TRANSFER);

            return(_abi.ToData());
        }
Esempio n. 7
0
        public static ContractABI Decode(Dictionary <string, List <string> > _mathodsAndArgs, string _hexData)
        {
            _hexData = _hexData.StartsWith("0x") ? _hexData.Substring(2) : _hexData;
            var _methodName = _hexData.Substring(0, 8);

            _hexData = _hexData.Substring(8);
            var _methods = _mathodsAndArgs.Where(t => t.Key == _methodName || t.Key == "0x" + _methodName);

            if (_methods.Count() == 0)
            {
                throw new Exception("No method equal the hexdata");
            }
            else if (_methods.Count() > 1)
            {
                throw new Exception("Too many method equal the hexdata");
            }
            var _methodArgs = _methods.First().Value;

            object[] _tempArray = new object[_methodArgs.Count];
            for (int i = 0; i < _methodArgs.Count; i++)
            {
                var _type  = _methodArgs[i];
                var _value = _hexData.Substring(0, 64);
                if (_type == "address")
                {
                    _value = _value.TrimStart('0');
                    if (_value.Length % 2 != 0)
                    {
                        _value = "0" + _value;
                    }
                    _tempArray[i] = "0x" + _value;
                }
                else if (!_type.Contains("[") && !_type.Contains("memory") && !_type.Contains("calldata"))
                {
                    _tempArray[i] = Data2Obj(_type, _hexData);
                }
                _hexData = _hexData.Substring(64);
            }
            //_hexData = _hexData.Substring(_methodArgs.Count * 64);//skip type define
            for (int i = 0; i < _methodArgs.Count; i++)
            {
                var _type = _methodArgs[i];
                if (_tempArray[i] != null)
                {
                    continue;
                }
                var _array = _type.Contains("[");
                if (_array)
                {
                    var   _isString            = _type.Contains("string");
                    var   _arrayLen            = int.Parse(_hexData.Substring(0, 64), System.Globalization.NumberStyles.HexNumber);
                    int[] _stringZeroPadLength = new int[_arrayLen];
                    _hexData = _hexData.Substring((_isString ? _arrayLen + 1 : 1) * 64);
                    object[] _subArray = new object[_arrayLen];
                    for (int j = 0; j < _arrayLen; j++)
                    {
                        int _dataLength = 64;
                        if (_isString)
                        {
                            int _stringLength = int.Parse(_hexData.Substring(0, 64), System.Globalization.NumberStyles.HexNumber) * 2;
                            _dataLength = _stringLength % 64 > 0 ? (_stringLength / 64 + 1) * 64 : _stringLength;
                        }
                        _hexData     = _isString ? _hexData.Substring(64) : _hexData;
                        _subArray[j] = Data2Obj(_type, _hexData, _dataLength);
                        _hexData     = _hexData.Substring(_dataLength);
                    }
                    _tempArray[i] = _subArray;
                }
                else
                {
                    int _dataLength = _type == "string"? int.Parse(_hexData.Substring(0, 64), System.Globalization.NumberStyles.HexNumber): 64;
                    _hexData      = _hexData.Substring(64);
                    _tempArray[i] = Data2Obj(_type, _hexData, _dataLength);
                    _hexData      = _hexData.Substring(_dataLength);
                }
            }
            ContractABI _re = new ContractABI("0x" + _methodName);

            _re.AddRange(_tempArray);
            return(_re);
        }