예제 #1
0
        public VakacoinRpc(string endPointUrl, string chainId = null)
        {
            try
            {
                EndPointUrl = endPointUrl;

                var vakaConfig = new VakaConfigurator()
                {
                    HttpEndpoint = EndPointUrl,
                };
                DefaultApi = new VakaApi(vakaConfig);

                if (string.IsNullOrEmpty(chainId))
                {
                    var getInfoResult = DefaultApi.GetInfo().Result;
                    chainId = getInfoResult.ChainId;
                }

                ChainId = chainId;
                DefaultApi.Config.ChainId = ChainId;
            }
            catch (Exception e)
            {
                Logger.Error(e);
                throw;
            }
        }
예제 #2
0
        public async Task <ReturnObject> SendTransactionAsync(string sFrom, string sTo, string sAmount, string sMemo,
                                                              string sPrivateKey)
        {
            try
            {
                var vakaConfig = new VakaConfigurator()
                {
                    SignProvider = new DefaultSignProvider(sPrivateKey),
                    HttpEndpoint = EndPointUrl,
                    ChainId      = ChainId
                };

                var vaka = new Vaka(vakaConfig);

                var result = await vaka.CreateTransaction(new Transaction()
                {
                    Actions = new List <Action>()
                    {
                        new Action()
                        {
                            Account       = SYSTEM_TOKEN_CONTRACT,
                            Authorization = new List <PermissionLevel>()
                            {
                                new PermissionLevel()
                                {
                                    Actor = sFrom, Permission = ACTIVE_PERMISSION
                                }
                            },
                            Name = TRANSFER_ACTION,
                            Data = new
                            {
                                from = sFrom, to = sTo, quantity = sAmount,
                                memo = sMemo
                            }
                        }
                    }
                });

                return(new ReturnObject
                {
                    Status = Status.STATUS_COMPLETED,
                    Data = result
                });
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }
예제 #3
0
 public VakaApi(VakaConfigurator config)
 {
     Config = config;
 }
예제 #4
0
        public ReturnObject CreateAccount(string accountName, string ownerPublicKey, string activePublicKey = "")
        {
            try
            {
                if (string.IsNullOrEmpty(activePublicKey))
                {
                    activePublicKey = ownerPublicKey;
                }

                // start CreateTransaction
                var vakaConfig = new VakaConfigurator()
                {
                    HttpEndpoint = EndPointUrl,
                    ChainId      = ChainId
                };

                var vaka = new Vaka(vakaConfig);

                vaka.CreateTransaction(new Transaction()
                {
                    Actions = new List <Action>()
                    {
                        new Action()
                        {
                            Account       = "vaka",
                            Authorization = new List <PermissionLevel>(),
                            Name          = "newaccountx",
                            Data          = new
                            {
                                name  = accountName,
                                owner = new
                                {
                                    threshold = 1,
                                    keys      = new List <object>()
                                    {
                                        new { key = ownerPublicKey, weight = 1 }
                                    },
                                    accounts = new List <object>(),
                                    waits    = new List <object>()
                                },
                                active = new
                                {
                                    threshold = 1,
                                    keys      = new List <object>()
                                    {
                                        new { key = activePublicKey, weight = 1 }
                                    },
                                    accounts = new List <object>(),
                                    waits    = new List <object>()
                                }
                            }
                        }
                    }
                });


                return(new ReturnObject
                {
                    Status = Status.STATUS_SUCCESS,
                    Data = accountName
                });
            }
            catch (Exception e)
            {
                Logger.Error(e);
                return(new ReturnObject
                {
                    Status = Status.STATUS_ERROR,
                    Message = e.Message
                });
            }
        }