public async Task CanSubmitPaymentTransaction()
        {
            IRippleClient rippleClient = new RippleClient("wss://s.altnet.rippletest.net:51233");
            await rippleClient.Connect();

            AccountInfo accountInfo = await rippleClient.AccountInfo("r9oxZ7NZW9ecSG8Fig2NGdLcWv9vFy8twE");

            IPaymentTransaction paymentTransaction = new PaymentTransaction();

            paymentTransaction.Account     = "r9oxZ7NZW9ecSG8Fig2NGdLcWv9vFy8twE";
            paymentTransaction.Destination = "rawNcFm6U1ecQjMLQveKyYGi2zgRutKeHS";
            paymentTransaction.Amount      = new Currency {
                ValueAsXrp = 20
            };
            paymentTransaction.Sequence = accountInfo.AccountData.Sequence;
            paymentTransaction.Fee      = new Currency {
                Value = "15"
            };

            var      json     = paymentTransaction.ToJson();
            TxSigner signer   = TxSigner.FromSecret("spzUVPgz5NmARYf3Sgk7bkYQ975BG");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await rippleClient.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 2
0
        public async Task CanEstablishTrust()
        {
            AccountInfo accountInfo = await client.AccountInfo("rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V");

            ITrustSetTransaction trustSet = new TrustSetTransaction();

            trustSet.LimitAmount = new Currency {
                CurrencyCode = "XYZ", Issuer = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT", Value = "1000000"
            };
            trustSet.Account  = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
            trustSet.Sequence = accountInfo.AccountData.Sequence;

            var      json     = trustSet.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await client.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var unsignedTxJson = @"{
                'Account': '19HVVcvqHvFocvwpdN4nB5AXXgg19qqpw3',
                'Amount': '1000',
                'Destination': '15ipnwHm6VV8TR8bpbkG5zo4FbgT5ZqrFq',
                'Fee': '10',
                'Flags': 2147483648,
                'Sequence': 1,
                'TransactionType' : 'Payment'
            }";

            // Sign with secret seed
            var secret  = "35tDMF67PWq8XmqY88CjBPZspfwX2"; // HisDivineShadow
            var signed1 = TxSigner.SignJson(JObject.Parse(unsignedTxJson), secret);

            Console.WriteLine(signed1.Hash);
            Console.WriteLine(signed1.TxJson);
            Console.WriteLine(signed1.TxBlob);

            // Sign with keypair
            var keyPair = new KeyPair("KzTZRtFzsus7RmRtVyspFtZLgM6VPgdZ6rSwWH2dHBEFrrLPpbaD");
            var signed2 = TxSigner.SignJson(JObject.Parse(unsignedTxJson), keyPair);

            Console.WriteLine(signed2.Hash);
            Console.WriteLine(signed2.TxJson);
            Console.WriteLine(signed2.TxBlob);
        }
Exemplo n.º 4
0
        public async Task CanCreateEscrow()
        {
            IRippleClient rippleClient = new RippleClient("wss://s.altnet.rippletest.net:51233");

            rippleClient.Connect();

            AccountInfo accountInfo = await rippleClient.AccountInfo("rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V");

            IEscrowCreateTransaction createTransaction = new EscrowCreateTransaction();

            createTransaction.Amount = new Currency {
                ValueAsXrp = 10
            };
            createTransaction.Account     = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
            createTransaction.FinishAfter = DateTime.UtcNow.AddMinutes(1);
            createTransaction.Destination = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT";
            createTransaction.Fee         = new Currency {
                Value = "11"
            };
            createTransaction.Sequence = accountInfo.AccountData.Sequence;

            var      json     = createTransaction.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await rippleClient.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 5
0
        public async Task CanFinishEscrow()
        {
            IRippleClient rippleClient = new RippleClient("wss://s.altnet.rippletest.net:51233");

            rippleClient.Connect();

            AccountInfo accountInfo = await rippleClient.AccountInfo("rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V");

            IEscrowFinishTransaction finishTransaction = new EscrowFinishTransaction();

            finishTransaction.Account       = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
            finishTransaction.Owner         = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
            finishTransaction.OfferSequence = 29;
            finishTransaction.Fee           = new Currency {
                Value = "11"
            };
            finishTransaction.Flags    = TransactionFlags.tfFullyCanonicalSig;
            finishTransaction.Sequence = accountInfo.AccountData.Sequence;

            var      json     = finishTransaction.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await rippleClient.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 6
0
        public async Task CanDeleteTrust()
        {
            AccountInfo accountInfo = await client.AccountInfo("rho3u4kXc5q3chQFKfn9S1ZqUCya1xT3t4");

            ITrustSetTransaction trustSet = new TrustSetTransaction();

            trustSet.Flags       = TrustSetFlags.tfSetNoRipple | TrustSetFlags.tfFullyCanonicalSig;
            trustSet.Account     = "rho3u4kXc5q3chQFKfn9S1ZqUCya1xT3t4";
            trustSet.LimitAmount = new Currency {
                ValueAsNumber = 0, Issuer = "rDLXQ8KEBn3Aw313bGzhEemx8cCPpGha3d", CurrencyCode = "PHP"
            };
            trustSet.QualityIn  = 0;
            trustSet.QualityOut = 0;
            trustSet.Sequence   = accountInfo.AccountData.Sequence;
            trustSet.Fee        = new Currency {
                Value = "12"
            };

            var      json     = trustSet.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await client.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 7
0
        public async Task CanReleaseEscrow()
        {
            IEscrowFinishTransaction escrowFinishTransaction = new EscrowFinishTransaction();

            escrowFinishTransaction.Account       = "rho3u4kXc5q3chQFKfn9S1ZqUCya1xT3t4";
            escrowFinishTransaction.Owner         = "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3";
            escrowFinishTransaction.OfferSequence = 10;
            escrowFinishTransaction.Fee           = new Currency {
                Value = "15"
            };
            escrowFinishTransaction.Flags = TransactionFlags.tfFullyCanonicalSig;

            var      json     = escrowFinishTransaction.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await client.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 8
0
        public void TestTxSigner()
        {
            List <String> mnemonic = new List <String>(singleVector.Split(" ", StringSplitOptions.RemoveEmptyEntries));
            // Create the network info
            NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: localbech32Hrp, lcdUrl: localTestUrl);

            // Build a transaction
            MsgSend msg = new MsgSend(
                fromAddress: "cosmos1hafptm4zxy5nw8rd2pxyg83c5ls2v62tstzuv2",
                toAddress: "cosmos12lla7fg3hjd2zj6uvf4pqj7atx273klc487c5k",
                amount: new List <StdCoin> {
                new StdCoin(denom: "uatom", amount: "100")
            }
                );
            // Fee
            StdFee fee = new StdFee(
                gas: "200000",
                amount: new List <StdCoin> {
                new StdCoin(denom: "uatom", amount: "250")
            }
                );
            StdTx tx = TxBuilder.buildStdTx(stdMsgs: new List <StdMsg> {
                msg
            }, fee: fee);
            // Create a wallet
            Wallet wallet = Wallet.derive(mnemonic, networkInfo);

            // Verify Wallet
            Assert.AreEqual(wallet.networkInfo.bech32Hrp, networkInfo.bech32Hrp);
            Assert.AreEqual(wallet.networkInfo.lcdUrl, networkInfo.lcdUrl);

            // Build the mockup server
            var _server = new MockHttpServer();
            //  I need this in order to get the correct data out of the mock server
            Dictionary <String, Object> accResponse  = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.AccountDataResponse);
            Dictionary <String, Object> NodeResponse = JsonConvert.DeserializeObject <Dictionary <String, Object> >(TestResources.NodeInfoResponse);

            // Initialize Server Response
            _server
            .WithService(localTestUrl)
            .Api("auth/accounts/{wallettAddress}", accResponse)
            .Api("node_info", NodeResponse);

            // Link the client to the retrieval classes
            HttpClient client = new HttpClient(_server);

            AccountDataRetrieval.client = client;
            NodeInfoRetrieval.client    = client;

            // Call without await to avoid marking test class as async
            StdTx signedTx = TxSigner.signStdTx(wallet: wallet, stdTx: tx).Result;

            Assert.AreEqual(signedTx.signatures.Count, 1);

            StdSignature signature = (signedTx.signatures.ToArray())[0];

            Assert.AreEqual(signature.publicKey.type, "tendermint/PubKeySecp256k1");
            Assert.AreEqual(signature.publicKey.value, "ArMO2T5FNKkeF2aAZY012p/cpa9+PqKqw2GcQRPhAn3w");
            Assert.AreEqual(signature.value, "m2op4CCBa39fRZD91WiqtBLKbUQI+1OWsc1tJkpDg+8FYB4y51KahGn26MskVMpTJl5gToIC1pX26hLbW1Kxrg==");
        }
Exemplo n.º 9
0
        public async Task CanFillOrder()
        {
            AccountInfo accountInfo = await client.AccountInfo("rEqtEHKbinqm18wQSQGstmqg9SFpUELasT");

            IOfferCreateTransaction offerCreate = new OfferCreateTransaction();

            offerCreate.Sequence  = accountInfo.AccountData.Sequence;
            offerCreate.TakerGets = new Currency {
                CurrencyCode = "XYZ", Issuer = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT", Value = "10"
            };
            offerCreate.TakerPays = new Currency {
                ValueAsXrp = 10
            };
            offerCreate.Expiration = DateTime.UtcNow.AddHours(1);
            offerCreate.Account    = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT";

            var      json     = offerCreate.ToJson();
            TxSigner signer   = TxSigner.FromSecret("xxxxxxx");
            SignedTx signedTx = signer.SignJson(JObject.Parse(json));

            SubmitBlobRequest request = new SubmitBlobRequest();

            request.TransactionBlob = signedTx.TxBlob;

            Submit result = await client.SubmitTransactionBlob(request);

            Assert.IsNotNull(result);
            Assert.AreEqual("tesSUCCESS", result.EngineResult);
            Assert.IsNotNull(result.Transaction.Hash);
        }
Exemplo n.º 10
0
    public async Task SendMoney(Decimal coin, String destination)
    {
        IPaymentTransaction paymentTransaction = new PaymentTransaction
        {
            Account     = wallet.Address,
            Destination = destination
        };
        Decimal dec = coin;

        paymentTransaction.Amount = new Currency {
            ValueAsXrp = dec
        };
        paymentTransaction.Sequence = accountInfo.AccountData.Sequence;

        TxSigner signer   = TxSigner.FromSecret(wallet.PrivateKey);
        SignedTx signedTx = signer.SignJson(JObject.Parse(paymentTransaction.ToJson()));

        SubmitBlobRequest request = new SubmitBlobRequest
        {
            TransactionBlob = signedTx.TxBlob
        };

        Submit result = await RippleClientUBC.GetClient().client.SubmitTransactionBlob(request);

        AccountInfo accoun = await RippleClientUBC.GetClient().client.AccountInfo(wallet.Address);

        AccountInfo accountIfo = await RippleClientUBC.GetClient().client.AccountInfo(destination);
    }
Exemplo n.º 11
0
 private static SignedTx GetSignedTx(StObject tx, TestAccount src)
 {
     if (tx.Has(Field.Signers) || tx.Has(Field.TxnSignature))
     {
         return(TxSigner.ValidateAndEncode(tx));
     }
     return(src.Signer.SignStObject(tx));
 }
Exemplo n.º 12
0
        public string CreateTxn(byte[] seed, string JsonTxn)
        {
            var walletIndex = 0;
            var keypair     = Ripple.Signing.K256.K256KeyGenerator.From128Seed(seed, walletIndex);
            var alt         = TxSigner.FromKeyPair(keypair).SignJson(JObject.Parse(JsonTxn));

            return(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(alt.Hash + "|" + alt.TxBlob + "|" + alt.TxJson)));
        }
Exemplo n.º 13
0
        /// Creates a transaction having the given [msgs] and [fee] inside,
        /// signs it with the given [Wallet] and sends it to the blockchain.
        /// Optional parameters can be [fee] and broadcasting [mode],
        /// that can be of type "sync", "async" or "block".
        public static async Task <TransactionResult> createSignAndSendTx(List <StdMsg> msgs, Wallet wallet, StdFee fee = null, BroadcastingMode mode = BroadcastingMode.SYNC)
        {
            if (fee == null)
            {
                // Set the default value for fee
                int msgsNumber = msgs.Count > 0 ? msgs.Count : 1;
                fee = GenericUtils.calculateDefaultFee(msgsNumber: msgsNumber, fee: defaultAmount, denom: defaultDenom, gas: defaultGas);
            }

            String modeStr  = MyEnumExtensions.ToEnumMemberAttrValue(mode);
            StdTx  stdTx    = TxBuilder.buildStdTx(stdMsgs: msgs, fee: fee);
            StdTx  signedTx = await TxSigner.signStdTx(wallet : wallet, stdTx : stdTx);

            // return await TxSender.broadcastStdTx(wallet: wallet, stdTx: signedTx, mode: modeStr);
            TransactionResult res = await TxSender.broadcastStdTx(wallet : wallet, stdTx : signedTx, mode : modeStr);

            return(res);
        }
 public void TestInitialize()
 {
     signer = TxSigner.FromSecret(fromAccountSecret);
 }
Exemplo n.º 15
0
 private void SetSigningKey(IKeyPair keyPair)
 {
     KeyPair = keyPair;
     Signer  = TxSigner.FromKeyPair(keyPair);
 }
        public async Task test_broadcastStdTx()
        {
            //This is the comparison class
            CompareLogic compareLogic = new CompareLogic();

            NetworkInfo networkInfo = new NetworkInfo(bech32Hrp: "did:com:", lcdUrl: "http://localhost:1317");

            //primo mnemonic
            String        mnemonicString1 = "gorilla soldier device force cupboard transfer lake series cement another bachelor fatigue royal lens juice game sentence right invite trade perfect town heavy what";
            List <String> mnemonic        = new List <String>(mnemonicString1.Split(" ", StringSplitOptions.RemoveEmptyEntries));

            //secondo mnemonic
            String        mnemonicString2 = "daughter conduct slab puppy horn wrap bone road custom acoustic adjust target price trip unknown agent infant proof whip picnic exact hobby phone spin";
            List <String> mnemonic2       = new List <String>(mnemonicString2.Split(" ", StringSplitOptions.RemoveEmptyEntries));


            Wallet wallet          = Wallet.derive(mnemonic, networkInfo);
            Wallet recipientWallet = Wallet.derive(mnemonic2, networkInfo);


            List <StdCoin> depositAmount = new List <StdCoin> {
                new StdCoin(denom: "ucommercio", amount: "10000")
            };

            var dict = new Dictionary <string, object>();

            dict.Add("from_address", wallet.bech32Address);
            dict.Add("to_address", recipientWallet.bech32Address);
            dict.Add("amount", depositAmount);


            StdMsg        testmsg     = new StdMsg("cosmos-sdk/MsgSend", dict);
            List <StdMsg> Listtestmsg = new List <StdMsg>();

            Listtestmsg.Add(testmsg);

            StdFee fee = new StdFee(depositAmount, "200000");

            //Invio
            try
            {
                var stdTx = TxBuilder.buildStdTx(Listtestmsg, "", fee);

                var signedStdTx = await TxSigner.signStdTx(wallet : wallet, stdTx : stdTx);

                var result = await TxSender.broadcastStdTx(wallet : wallet, stdTx : signedStdTx);

                if (result.success)
                {
                    Console.WriteLine("Tx send successfully:\n$lcdUrl/txs/${result.hash}");
                }
                else
                {
                    Console.WriteLine("Tx error message:\n${result.error?.errorMessage}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error while testing Sacco:\n$error");
            }
        }
Exemplo n.º 17
0
 public void StaticSignJson_ValidTransactionAndEd25559Secret_ValidSignature()
 {
     AssertOk(TxSigner.SignJson(JObject.Parse(UnsignedTxJson), Secret));
 }