Example #1
0
 /// <summary>
 /// Client wrapper to interact with eos blockchains.
 /// </summary>
 /// <param name="config">Configures client parameters</param>
 public Eos(EosConfigurator config)
 {
     EosConfig = config;
     if (EosConfig == null)
     {
         throw new ArgumentNullException("config");
     }
     Api           = new EosApi(EosConfig);
     AbiSerializer = new AbiSerializationProvider(Api);
 }
Example #2
0
 /// <summary>
 /// Client wrapper to interact with eos blockchains.
 /// </summary>
 /// <param name="config">Configures client parameters</param>
 public EosBase(EosConfigurator config, IHttpHelper httpHelper)
 {
     EosConfig = config;
     if (EosConfig == null)
     {
         throw new ArgumentNullException("config");
     }
     Api           = new EosApi(EosConfig, httpHelper);
     AbiSerializer = new AbiSerializationProvider(Api);
 }
Example #3
0
 public ChainManager(EosConfigurator eosConfig)
 {
     m_EosConfig  = eosConfig;
     m_EosApi     = new EosApi(eosConfig, new HttpHandler());
     m_HttpClient = new HttpClient()
     {
         BaseAddress = new Uri(m_EosConfig.HttpEndpoint)
     };
     m_HttpClient.DefaultRequestHeaders.Connection.Add("keep-alive");
 }
Example #4
0
        public SignUnitTests()
        {
            EosConfig = new EosConfigurator()
            {
                SignProvider = new DefaultSignProvider("5K57oSZLpfzePvQNpsLS6NfKXLhhRARNU13q6u2ZPQCGHgKLbTA"),

                //HttpEndpoint = "https://nodes.eos42.io", //Mainnet
                //ChainId = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"

                HttpEndpoint = "https://nodeos01.btuga.io",
                ChainId      = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
            };
            DefaultApi = new EosApi(EosConfig);
        }
Example #5
0
        public SignUnitTests()
        {
            EosConfig = new EosConfigurator()
            {
                SignProvider = new DefaultSignProvider("5K57oSZLpfzePvQNpsLS6NfKXLhhRARNU13q6u2ZPQCGHgKLbTA"),

                //HttpEndpoint = "https://nodes.eos42.io", //Mainnet
                //ChainId = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"

                HttpEndpoint = "https://jungle2.cryptolions.io",
                ChainId      = "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473"
            };
            DefaultApi = new EosApi(EosConfig, new HttpHandler());
        }
Example #6
0
 public TransactionsManager(
     EosConfigurator eosConfig,
     ABIService abiService,
     string connectionString,
     string databaseName,
     string transactionCollectionName,
     string transferCollectionName)
 {
     this.m_EosConfig                 = eosConfig;
     this.m_ABIService                = abiService;
     this.m_MongoClient               = (IMongoClient) new MongoClient(connectionString);
     this.m_MongoDatabase             = this.m_MongoClient.GetDatabase(databaseName, (MongoDatabaseSettings)null);
     this.m_TransactionCollectionName = transactionCollectionName;
     this.m_TransferCollectionName    = transferCollectionName;
     this.m_EosApi        = new EosApi(this.m_EosConfig, new HttpHandler());
     this.m_AbiSerializer = new core.Services.AbiSerializationProvider(this.m_EosApi);
 }
        public ApiUnitTests()
        {
            var eosConfig = new EosConfigurator()
            {
                SignProvider = new DefaultSignProvider("5K57oSZLpfzePvQNpsLS6NfKXLhhRARNU13q6u2ZPQCGHgKLbTA"),

                //HttpEndpoint = "https://nodes.eos42.io", //Mainnet
                //ChainId = "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906"

                HttpEndpoint = "https://jungle2.cryptolions.io",
                ChainId      = "e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473"

                               //HttpEndpoint = "http://localhost:8888",
                               //ChainId = "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f"
            };
            var eosApi = new EosApi(eosConfig, new HttpHandler());

            ApiUnitTestCases = new ApiUnitTestCases(eosConfig, eosApi);
        }
        /// <summary>
        /// Calculate required keys to sign the given transaction
        /// </summary>
        /// <param name="availableKeys">available public keys list</param>
        /// <param name="trx">transaction requiring signatures</param>
        /// <returns>required public keys</returns>
        public static async Task <List <string> > GetRequiredKeys(EosApi api, core.Services.AbiSerializationProvider abiSerializer, List <string> availableKeys, Transaction trx)
        {
            int actionIndex  = 0;
            var abiResponses = await abiSerializer.GetTransactionAbis(trx);

            foreach (var action in trx.context_free_actions)
            {
                action.data = SerializationHelper.ByteArrayToHexString(abiSerializer.SerializeActionData(action, abiResponses[actionIndex++]));
            }

            foreach (var action in trx.actions)
            {
                action.data = SerializationHelper.ByteArrayToHexString(abiSerializer.SerializeActionData(action, abiResponses[actionIndex++]));
            }

            return((await api.GetRequiredKeys(new GetRequiredKeysRequest()
            {
                available_keys = availableKeys,
                transaction = trx
            })).required_keys);
        }
        public static async Task <string> CreateTransaction(Transaction trx)
        {
            core.Services.AbiSerializationProvider.Prefix = "VHKD";
            var eosConfig = new EosConfigurator()
            {
                HttpEndpoint  = "http://192.168.1.61", //Mainnet
                ExpireSeconds = 60,
                ChainId       = "afe97f023511453c09c64f5bb655e7f4dc6694685aff7231219964e9cc521585",
                SignProvider  = new core.Services.DefaultSignProvider("5JNNWKaCoWvN5xojDXsW38Z6uoLmvM9NPh3coQD5z3TgsuY4nmt", "VHKD")
            };
            var api           = new EosApi(eosConfig, new HttpHandler());
            var abiSerializer = new core.Services.AbiSerializationProvider(api);

            if (eosConfig.SignProvider == null)
            {
                throw new ArgumentNullException("SignProvider");
            }

            GetInfoResponse getInfoResult = null;
            string          chainId       = eosConfig.ChainId;

            if (string.IsNullOrWhiteSpace(chainId))
            {
                getInfoResult = await api.GetInfo();

                chainId = getInfoResult.chain_id;
            }

            if (trx.expiration == DateTime.MinValue ||
                trx.ref_block_num == 0 ||
                trx.ref_block_prefix == 0)
            {
                if (getInfoResult == null)
                {
                    getInfoResult = await api.GetInfo();
                }

                var getBlockResult = await api.GetBlock(new GetBlockRequest()
                {
                    block_num_or_id = getInfoResult.last_irreversible_block_num.ToString()
                });

                trx.expiration       = getInfoResult.head_block_time.AddSeconds(eosConfig.ExpireSeconds);
                trx.ref_block_num    = (UInt16)(getInfoResult.last_irreversible_block_num & 0xFFFF);
                trx.ref_block_prefix = getBlockResult.ref_block_prefix;
            }

            var packedTrx = await abiSerializer.SerializePackedTransaction(trx);

            var availableKeys = await eosConfig.SignProvider.GetAvailableKeys();

            var requiredKeys = await GetRequiredKeys(api, abiSerializer, availableKeys.ToList(), trx);

            IEnumerable <string> abis = null;

            if (trx.actions != null)
            {
                abis = trx.actions.Select(a => a.account);
            }

            var signatures = await eosConfig.SignProvider.Sign(chainId, requiredKeys, packedTrx, abis);

            var result = await api.PushTransaction(new PushTransactionRequest()
            {
                signatures  = signatures.ToArray(),
                compression = 0,
                packed_context_free_data = "",
                packed_trx = SerializationHelper.ByteArrayToHexString(packedTrx)
            });

            return(result.transaction_id);
        }
        public AbiSerializationProvider(EosApi api)
        {
            this.Api = api;

            TypeWriters = new Dictionary <string, Action <MemoryStream, object> >()
            {
                { "int8", WriteByte },
                { "uint8", WriteByte },
                { "int16", WriteUint16 },
                { "uint16", WriteUint16 },
                { "int32", WriteUint32 },
                { "uint32", WriteUint32 },
                { "int64", WriteInt64 },
                { "uint64", WriteUint64 },
                { "int128", WriteInt128 },
                { "uint128", WriteUInt128 },
                { "varuint32", WriteVarUint32 },
                { "varint32", WriteVarInt32 },
                { "float32", WriteFloat32 },
                { "float64", WriteFloat64 },
                { "float128", WriteFloat128 },
                { "bytes", WriteBytes },
                { "bool", WriteBool },
                { "string", WriteString },
                { "name", WriteName },
                { "asset", WriteAsset },
                { "time_point", WriteTimePoint },
                { "time_point_sec", WriteTimePointSec },
                { "block_timestamp_type", WriteBlockTimestampType },
                { "symbol_code", WriteSymbolCode },
                { "symbol", WriteSymbolString },
                { "checksum160", WriteChecksum160 },
                { "checksum256", WriteChecksum256 },
                { "checksum512", WriteChecksum512 },
                { "public_key", WritePublicKey },
                { "private_key", WritePrivateKey },
                { "signature", WriteSignature },
                { "extended_asset", WriteExtendedAsset }
            };

            TypeReaders = new Dictionary <string, ReaderDelegate>()
            {
                { "int8", ReadByte },
                { "uint8", ReadByte },
                { "int16", ReadUint16 },
                { "uint16", ReadUint16 },
                { "int32", ReadUint32 },
                { "uint32", ReadUint32 },
                { "int64", ReadInt64 },
                { "uint64", ReadUint64 },
                { "int128", ReadInt128 },
                { "uint128", ReadUInt128 },
                { "varuint32", ReadVarUint32 },
                { "varint32", ReadVarInt32 },
                { "float32", ReadFloat32 },
                { "float64", ReadFloat64 },
                { "float128", ReadFloat128 },
                { "bytes", ReadBytes },
                { "bool", ReadBool },
                { "string", ReadString },
                { "name", ReadName },
                { "asset", ReadAsset },
                { "time_point", ReadTimePoint },
                { "time_point_sec", ReadTimePointSec },
                { "block_timestamp_type", ReadBlockTimestampType },
                { "symbol_code", ReadSymbolCode },
                { "symbol", ReadSymbolString },
                { "checksum160", ReadChecksum160 },
                { "checksum256", ReadChecksum256 },
                { "checksum512", ReadChecksum512 },
                { "public_key", ReadPublicKey },
                { "private_key", ReadPrivateKey },
                { "signature", ReadSignature },
                { "extended_asset", ReadExtendedAsset }
            };
        }
 public ApiUnitTestCases(EosConfigurator eosConfig, EosApi api)
 {
     EosConfig  = eosConfig;
     DefaultApi = api;
 }