Beispiel #1
0
        public async Task SerializeAndSignMultiActionTx()
        {
            var keyStore = new InMemoryKeyStore();
            var keyPair  = KeyPair.FromString("ed25519:2wyRcSwSuHtRVmkMCGjPwnzZmQLeXLzLLyED1NDMt4BjnKgQL6tF85yBx6Jr26D2dUNeC716RBoTxntVHsegogYw");
            await keyStore.SetKeyAsync("test", "test.near", keyPair);

            var publicKey = keyPair.GetPublicKey();

            var actions = new[]
            {
                Action.CreateAccount(),
                Action.DeployContract(new byte[] { 1, 2, 3 }),
                Action.FunctionCall("qqq", new byte[] { 1, 2, 3 }, 1000, 1000000),
                Action.Transfer(123),
                Action.Stake(1000000, publicKey),
                Action.AddKey(publicKey, AccessKey.FunctionCallAccessKey("zzz", new [] { "www" }, null)),
                Action.DeleteKey(publicKey),
                Action.DeleteAccount("123")
            };

            var blockHash = new ByteArray32()
            {
                Buffer = Base58.Decode("244ZQ9cgj3CQ6bWBdytfrJMuMQ1jdXLFGnr4HhvtCTnM")
            };
            var signedTransaction = await SignedTransaction.SignTransactionAsync("123", 1, actions, blockHash, new InMemorySigner(keyStore), "test.near", "test");

            const string expected = "Fo3MJ9XzKjnKuDuQKhDAC6fra5H2UWawRejFSEpPNk3Y";
            var          actual   = Base58.Encode(signedTransaction.Item1);

            Assert.AreEqual(expected, actual);
        }
Beispiel #2
0
        public async Task <FinalExecutionOutcome> CreateAccountAsync(string newAccountId, PublicKey publicKey,
                                                                     UInt128 amount)
        {
            var accessKey = AccessKey.FullAccessKey();
            var actions   = new[]
            { Action.CreateAccount(), Action.Transfer(amount), Action.AddKey(publicKey, accessKey) };
            var result = await SignAndSendTransactionAsync(newAccountId, actions);

            return(result);
        }
Beispiel #3
0
        public async Task <Account> CreateAndDeployContractAsync(string contractId, string publicKey, byte[] data,
                                                                 UInt128 amount)
        {
            var accessKey = AccessKey.FullAccessKey();
            var actions   = new[]
            {
                Action.CreateAccount(), Action.Transfer(amount), Action.AddKey(new PublicKey(publicKey), accessKey),
                Action.DeployContract(data)
            };

            await SignAndSendTransactionAsync(contractId, actions);

            var contractAccount = new Account(_connection, contractId);

            return(contractAccount);
        }
Beispiel #4
0
        public async Task <FinalExecutionOutcome> AddKeyAsync(string publicKey,
                                                              string methodName = "", string contractId = "")
        {
            AccessKey accessKey;

            if (string.IsNullOrEmpty(contractId) || string.IsNullOrWhiteSpace(contractId))
            {
                accessKey = AccessKey.FullAccessKey();
            }
            else
            {
                accessKey = AccessKey.FunctionCallAccessKey(contractId, (string.IsNullOrWhiteSpace(methodName) || string.IsNullOrEmpty(methodName)) ? Array.Empty <string>() : new[] { methodName });
            }
            var result = await SignAndSendTransactionAsync(_accountId, new[] { Action.AddKey(new PublicKey(publicKey), accessKey) });

            return(result);
        }