Example #1
0
        public async Task AbiJsonToBinTest()
        {
            var abiJsonToBinParams = new AbiJsonToBinParams
            {
                Code   = "hackathon",
                Action = "transfer",
                Args   = new Transfer
                {
                    From   = "test1",
                    To     = "test1",
                    Amount = "1000 VIM",
                }
            };

            var resp = await Api.AbiJsonToBin(abiJsonToBinParams, CancellationToken.None);

            Console.WriteLine(resp.Error);
            Assert.IsTrue(resp.IsSuccess);
            Console.WriteLine(JsonConvert.SerializeObject(resp.Result));

            var obj = await Api.CustomPostRequest <JObject>("v1/chain/abi_json_to_bin", abiJsonToBinParams, CancellationToken.None);

            TestPropetries(resp.Result.GetType(), obj.Result);
            Console.WriteLine("----------------------------------------------------------------------------");
            Console.WriteLine(JsonConvert.SerializeObject(obj));
        }
Example #2
0
 /// <summary>
 /// Transform action data to packed binary format
 /// </summary>
 /// <param name="code">smart contract account name</param>
 /// <param name="action">action name</param>
 /// <param name="data">action </param>
 /// <returns></returns>
 public async Task <string> AbiJsonToBin(string code, string action, object data)
 {
     return((await Api.AbiJsonToBin(new AbiJsonToBinRequest()
     {
         code = code,
         action = action,
         args = data
     })).binargs);
 }
Example #3
0
        public async Task PushTransactionTest()
        {
            var abiJsonToBinArgs = new AbiJsonToBinParams
            {
                Code   = ContractInfo.ContractName,
                Action = CreatePostActionName,
                Args   = new CreatePostArgs
                {
                    UrlPhoto       = "test_1_url",
                    AccountCreator = User.Login,
                    IpfsHashPhoto  = "test_1_hash"
                                     //ParentPost = 1
                }
            };
            var abiJsonToBin = await Api.AbiJsonToBin(abiJsonToBinArgs, CancellationToken);

            Assert.IsFalse(abiJsonToBin.IsError);

            var args = new CreateTransactionArgs
            {
                Actions = new[]
                {
                    new Action
                    {
                        Account       = User.Login,
                        Name          = CreatePostActionName,
                        Authorization = new[]
                        {
                            new PermissionLevel
                            {
                                Actor      = User.Login,
                                Permission = "active"
                            }
                        },
                        Data = abiJsonToBin.Result.Binargs
                    }
                },
                PrivateKeys = new List <byte[]> {
                    User.PrivateActiveKey
                }
            };

            var packedTransaction = await Api.CreatePackedTransaction(args, CancellationToken);

            var resp = await Api.PushTransaction(packedTransaction, CancellationToken);

            WriteLine(resp);

            Assert.IsFalse(resp.IsError);
        }
Example #4
0
        public async Task AbiJsonToBinTest()
        {
            var abiJsonToBinArgs = new AbiJsonToBinParams
            {
                Code   = ContractInfo.ContractName,
                Action = CreatePostActionName,
                Args   = new CreatePostArgs
                {
                    UrlPhoto       = "test_1_url",
                    AccountCreator = User.Login,
                    IpfsHashPhoto  = "test_1_hash"
                                     //ParentPost = 1
                }
            };

            var resp = await Api.AbiJsonToBin(abiJsonToBinArgs, CancellationToken);

            TestPropetries(resp);
        }
Example #5
0
        public async Task WalletSignTrxTest()
        {
            var abiJsonToBinArgs = new AbiJsonToBinParams
            {
                Code   = ContractInfo.ContractName,
                Action = CreatePostActionName,
                Args   = new CreatePostArgs
                {
                    UrlPhoto       = "test_1_url",
                    AccountCreator = User.Login,
                    IpfsHashPhoto  = "test_1_hash"
                                     //ParentPost = 1
                }
            };
            var abiJsonToBin = await Api.AbiJsonToBin(abiJsonToBinArgs, CancellationToken);

            Assert.IsFalse(abiJsonToBin.IsError);

            var accountParams = new GetAccountParams
            {
                AccountName = User.Login
            };

            var unlock = await Api.WalletUnlock(User.Login, User.Password, CancellationToken);

            Assert.IsFalse(unlock.IsError);

            var accR = await Api.GetAccount(accountParams, CancellationToken);

            Assert.IsFalse(accR.IsError);

            var publicKeys = accR.Result.Permissions.First(p => p.PermName == "active").RequiredAuth.Keys.Select(k => k.Key).ToArray();

            var args = new CreateTransactionArgs
            {
                Actions = new[]
                {
                    new EOS.Models.Action
                    {
                        Account       = User.Login,
                        Name          = CreatePostActionName,
                        Authorization = new[]
                        {
                            new PermissionLevel
                            {
                                Actor      = User.Login,
                                Permission = "active"
                            }
                        },
                        Data = abiJsonToBin.Result.Binargs
                    }
                },
                PrivateKeys = new List <byte[]> {
                    User.PrivateActiveKey
                }
            };
            var trx = await Api.CreateTransaction(args, CancellationToken);

            var infoResp = await Api.GetInfo(CancellationToken.None);

            var info = infoResp.Result;

            var resp = await Api.WalletSignTrx(trx, publicKeys, info.ChainId, CancellationToken.None);

            WriteLine(resp);
            Assert.IsFalse(resp.IsError);

            var wlock = await Api.WalletLock(User.Login, CancellationToken);

            Assert.IsFalse(wlock.IsError);
        }