Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void KeysTest()
        {
            const string seed =
                "68bc96f22b3a447cdb1f82b9935396ea4dca90831c385e24970c70e3b17480e3460830a1b14db6f2eb021bf8628c8502e992ad74f6babd3fabbe164dd97e8c35";

            var key = new Key(seed.HexDecode(), 0);

            _testOutputHelper.WriteLine(key.PrivateKey.ToHex());
        }
Exemplo n.º 4
0
        public void VerifySignTest()
        {
            var pk   = "02fbeb29c5dbbebe7a64d3bf441878ce8c4eb12f379ca41eb9237c362ca2431f8f".HexDecode();
            var sign =
                "73b306abb83df6d1533e16c62b23ce7c1e62f9ab648e0db4fe18326b9233340719b22197a1ceb8aeddf1bf73aa7da782b816205bfa01b75091f0f297ae0fffd8"
                .HexDecode();
            var msg = Encoding.UTF8.GetBytes("Hello World.");

            Assert.True(Key.Verify(sign, msg, pk));
        }