Example #1
0
        public TransactionPayload SignWith(TransactionPayload tx, Account signer, bool getNonce = false)
        {
            if (signer == null)
            {
                throw new Exception("account not exists");
            }
            try
            {
                if (getNonce)
                {
                    var result = _zil.GetBalance(signer.Address).Result;
                    tx.Nonce = (int)result.Nonce + 1;
                }
            }
            catch (Exception e)
            {
                throw new Exception("cannot get nonce", e);
            }

            tx.PubKey = signer.GetPublicKey();
            byte[]    message   = tx.Encode();
            Signature signature = Schnorr.Sign(signer.KeyPair, message);

            tx.Signature = (signature.ToString().ToLower());
            return(tx);
        }
Example #2
0
    static void DemoP2PScriptFunction()
    {
        StructTag tag = new StructTag(
            AccountAddress.valueOf(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }),
            new Identifier("XDX"),
            new Identifier("XDX"),
            new ValueArray <TypeTag>(new List <TypeTag>().ToArray())
            );

        TypeTag token = new TypeTag.Struct(tag);

        AccountAddress payee = AccountAddress.valueOf(
            new byte[] { 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 });

        ulong amount = 1234567;
        TransactionPayload payload =
            Helpers.encode_peer_to_peer_with_metadata_script_function(
                token,
                payee,
                amount,
                new ValueArray <byte>(new List <byte>().ToArray()),
                new ValueArray <byte>(new List <byte>().ToArray())
                );

        ScriptFunctionCall.PeerToPeerWithMetadata call = (ScriptFunctionCall.PeerToPeerWithMetadata)Helpers.DecodeScriptFunctionPayload(payload);
        Debug.Assert(call.amount.Equals(amount), string.Format("call.amount is {0}. Expecting {1}", call.amount, amount));
        Debug.Assert(call.payee.Equals(payee), string.Format("call.payee is {0}. Expecting {1}", call.payee, payee));

        byte[] output = payload.BcsSerialize();
        foreach (byte o in output)
        {
            Console.Write(((int)o & 0xFF) + " ");
        }
        Console.WriteLine();
    }
Example #3
0
        public async Task <Transaction.Info> CreateTransaction(TransactionPayload payload)
        {
            var res = await _client.CreateTransaction(payload);

            if (res.Error)
            {
                throw new Exception(res.Message);
            }

            return(((JToken)res.Result).ToObject <Transaction.Info>());
        }
Example #4
0
        public TransactionPayload Sign(TransactionPayload transaction)
        {
            if (transaction.ToAddr.ToUpper().StartsWith("0X"))
            {
                transaction.ToAddr = transaction.ToAddr.Substring(2);
            }

            string address = CryptoUtil.GetAddressFromPublicKey(transaction.PubKey).ToUpper();

            if (_curr == null)
            {
                throw new Exception("Could not sign the transaction with" + address + "  as it does not exist");
            }
            return(SignWith(transaction, _curr));
        }
        /// <summary>
        ///     Announce aggregate bonded
        /// </summary>
        /// <param name="signedTransaction">The signedTransaction</param>
        /// <returns>IObservable&lt;TransactionAnnounceResponse&gt;</returns>
        public IObservable <TransactionAnnounceResponse> AnnounceAggregateBonded(SignedTransaction signedTransaction)
        {
            if (signedTransaction == null)
            {
                throw new ArgumentException(nameof(signedTransaction));
            }

            var route = $"{BasePath}/transactions/partial";

            var payload = new TransactionPayload
            {
                Payload = signedTransaction.Payload
            };

            return(Observable.FromAsync(async ar =>
                                        await route.PutJsonAsync(payload).ReceiveJson <AnnounceTransactionInfoDTO>())
                   .Select(m => new TransactionAnnounceResponse(m.Message)));
        }
Example #6
0
        public async Task CreateTransactionHasId()
        {
            //TODO figure out how to create transaction tests with signatures

            var tx = new TransactionPayload()
            {
                ToAddr   = "4C352ba2Bd33245CDA180699e6B5c6334AB5dC26",
                Amount   = "1000000000000",
                GasPrice = "1000000000",
                GasLimit = "1",
                Code     = "",
                Data     = "",
                Priority = false
            };

            tx.SetVersion(true);
            var signed = _wallet.SignWith(tx, _account, true);
            var info   = await _zil.CreateTransaction(signed);

            Assert.IsNotNull(info);
        }
 protected virtual void OnTransactionRollingBackError(TransactionPayload payload)
 {
 }
 protected virtual void OnTransactionRolledBack(TransactionPayload payload)
 {
 }
 protected virtual void OnTransactionCommittingError(TransactionPayload payload)
 {
 }
Example #10
0
 //Transaction-related methods
 public Rep <CreateTxResult> CreateTransaction(TransactionPayload payload)
 {
     return(Send <CreateTxResult, TransactionPayload>("CreateTransaction", payload));
 }