async Task WriteAsync(BinaryWriter writer, Action action) { writer.Write(Base32.Encode(action.Account)); writer.Write(Base32.Encode(action.Name)); // Authorizations var authorizations = action.Authorization?.ToArray() ?? new Authorization[0]; writer.WriteVarUInt32((uint)authorizations.Length); foreach (var auth in authorizations) { Write(writer, auth); } // Arguments var hexData = action.HexData; if (string.IsNullOrEmpty(hexData)) { var args = await Api.AbiJsonToBinAsync(action.Account, action.Name, action.Data); hexData = args.BinArgs; } var bytes = Hex.Decode(hexData); writer.WriteVarUInt32((byte)bytes.Length); writer.Write(bytes); }
public async Task SignTransactionTest() { var op = new BuyramAction { Account = User.Login, Args = new Buyram { Payer = User.Login, Receiver = User.Login, Quant = new Asset("0.001 EOS") }, Authorization = new[] { new PermissionLevel { Actor = User.Login, Permission = "active" } } }; var initOpRez = await Api.AbiJsonToBinAsync(new[] { op }, CancellationToken).ConfigureAwait(false); if (initOpRez.IsError) { WriteLine(initOpRez); Assert.Fail(); } var infoResp = await Api.GetInfoAsync(CancellationToken).ConfigureAwait(false); if (infoResp.IsError) { WriteLine(infoResp); Assert.Fail(); } var info = infoResp.Result; var blockArgs = new GetBlockParams { BlockNumOrId = info.HeadBlockId }; var getBlock = await Api.GetBlockAsync(blockArgs, CancellationToken).ConfigureAwait(false); if (getBlock.IsError) { WriteLine(getBlock); Assert.Fail(); } var block = getBlock.Result; var trx = new SignedTransaction { Actions = new[] { op }, RefBlockNum = (ushort)(block.BlockNum & 0xffff), RefBlockPrefix = block.RefBlockPrefix, Expiration = block.Timestamp.Value.AddSeconds(30) }; await Api.WalletOpenAsync(User.Login, CancellationToken).ConfigureAwait(false); await Api.WalletUnlockAsync(User.Login, User.Password, CancellationToken).ConfigureAwait(false); var resp = await Api.WalletSignTransactionAsync(trx, new[] { new PublicKey(User.PublicActiveWif), }, info.ChainId, CancellationToken.None).ConfigureAwait(false); await Api.WalletLockAsync(User.Login, CancellationToken).ConfigureAwait(false); WriteLine(resp); Assert.IsFalse(resp.IsError); Assert.IsTrue(resp.Result.Signatures.Length == 1); }
public async Task AbiJsonToBinTest() { var args = new AbiJsonToBinParams { Code = NewaccountAction.ContractName, Action = NewaccountAction.ActionName, Args = new Newaccount { Creator = "eosio", Newact = "qwdfvbmfkrt", Owner = new Ditch.EOS.Contracts.Eosio.Structs.Authority { Threshold = 1, Keys = new[] { new Ditch.EOS.Contracts.Eosio.Structs.KeyWeight { Key = new PublicKey("EOS6JQaiy5wpCvwyBauN4odnyqcutboxMk2bYkC3e2nmUubBsBbZ8"), Weight = 1 } }, Accounts = new[] { new Ditch.EOS.Contracts.Eosio.Structs.PermissionLevelWeight { Weight = 1, Permission = new PermissionLevel() { Permission = "owner", Actor = "qwdfvbmfkrt" } } }, Waits = new[] { new WaitWeight() { Weight = 1, WaitSec = 0 } } }, Active = new Ditch.EOS.Contracts.Eosio.Structs.Authority { Threshold = 1, Keys = new[] { new Ditch.EOS.Contracts.Eosio.Structs.KeyWeight { Weight = 1, Key = new PublicKey("EOS7z5qpGxAKZRgDmVCc2p5VZocumssfDoFMi5BNEsSocFWu4dXB2") } }, Accounts = new[] { new Ditch.EOS.Contracts.Eosio.Structs.PermissionLevelWeight { Weight = 1, Permission = new PermissionLevel() { Permission = "active", Actor = "qwdfvbmfkrt" } } }, Waits = new[] { new WaitWeight() { Weight = 1, WaitSec = 0 } } } } }; var resp = await Api.AbiJsonToBinAsync(args, CancellationToken).ConfigureAwait(false); TestPropetries(resp); }