Пример #1
0
        public void WalletAddressTest()
        {
            var w = _service.CreateWallet();

            _testOutputHelper.WriteLine(w.Mnemonic);
            _testOutputHelper.WriteLine(w.Seed);
            _testOutputHelper.WriteLine(w.PrivateKey);
            _testOutputHelper.WriteLine(w.PublicKey);
            _testOutputHelper.WriteLine(w.Address);

            var key        = new Key(w.Seed.HexDecode(), 0);
            var walletKeys = key.ToWallet();

            var key2        = new Key(w.PrivateKey.HexDecode());
            var walletKeys2 = key2.ToWallet();

            Assert.Equal(w.PrivateKey, key.PrivateKey.ToHex());

            Assert.Equal(w.Address, walletKeys.Base58Address);
            Assert.Equal(w.Address, walletKeys2.Base58Address);

            var pk = "02fbeb29c5dbbebe7a64d3bf441878ce8c4eb12f379ca41eb9237c362ca2431f8f";
            var expectedAddress = "SC8Ce9JAA9GuzBhrCQE8Mx4fMuNcsHJVB7w7";

            var wallet = new Wallet(pk.HexDecode());

            Assert.Equal(expectedAddress, wallet.Base58Address);
        }
Пример #2
0
        public async Task TestManualTx()
        {
            const string  receiver   = "SCpk7rqhA56LRzv3PKHfr31ptoSsCSeC5xn";
            const string  privateKey = " ";
            const decimal amount     = 1000m;

            const ulong gasPrice   = 3;
            const ulong gas        = Constants.Commission;
            const ulong commission = gas * gasPrice;

            var key = new Key(privateKey.HexDecode());

            var wallet = key.ToWallet();

            var balance = await _httpService.GetBalance(Network, wallet.Base58Address);

            _testOutputHelper.WriteLine($"confirmed balance: {balance.ConfirmedAmount}");
            _testOutputHelper.WriteLine($"unconfirmed balance: {balance.UnconfirmedAmount}");

            var nonce = await _httpService.GetNonce(Network, wallet.Base58Address);

            const ulong txAmount = (ulong)(amount * (decimal)MoneyUnit.BTC);

            var tx = new TransactionRequest()
                     .AddCommission(gasPrice, gas)
                     .AddSender(wallet.Base58Address, key, txAmount + commission, nonce.ConfirmedNonce)
                     .AddTransfer(receiver, txAmount)
                     .Sign();

            // _testOutputHelper.WriteLine(tx.ToJson());

            var response = await _httpService.Send(Network, tx);

            _testOutputHelper.WriteLine(response.Result);
        }