Пример #1
0
        public void CreatePrivateKey()
        {
            var networkParameters = NetworkParameters.TestNet();

            var keyPair = new EcKey();

            //the tostring displays public and private.
            Logger.Debug(keyPair);

            //private key in format for import/export from bitcoin-qt
            Logger.Debug(keyPair.GetPrivateKeyEncoded(networkParameters));

            //public key. this is not the address.
            Logger.Debug(keyPair.PublicKey);

            //create an address
            var address = keyPair.ToAddress(networkParameters);

            //address.
            Logger.Debug(address.ToString());
        }
Пример #2
0
        public void BasicSpending()
        {
            // We'll set up a wallet that receives a coin, then sends a coin of lesser value and keeps the change.
            var v1 = Utils.ToNanoCoins(1, 0);
            var t1 = TestUtils.CreateFakeTx(Params, v1, _myAddress);

            _defaultWallet.Receive(t1, null, BlockChain.NewBlockType.BestChain);
            Assert.AreEqual(v1, _defaultWallet.GetBalance());
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.Unspent));
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.All));

            var k2 = new EcKey();
            var v2 = Utils.ToNanoCoins(0, 50);
            var t2 = _defaultWallet.CreateSend(k2.ToAddress(Params), v2);
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.Unspent));
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.All));

            // Do some basic sanity checks.
            Assert.AreEqual(1, t2.TransactionInputs.Count);
            Assert.AreEqual(_myAddress, t2.TransactionInputs[0].ScriptSig.FromAddress);

            // We have NOT proven that the signature is correct!

            _defaultWallet.ConfirmSend(t2);
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.Pending));
            Assert.AreEqual(1, _defaultWallet.GetPoolSize(WalletPool.Spent));
            Assert.AreEqual(2, _defaultWallet.GetPoolSize(WalletPool.All));
        }
Пример #3
0
 public void SetUp()
 {
     var myKey = new EcKey();
     _myAddress = myKey.ToAddress(Params);
     _defaultWallet = new DefaultWallet(Params);
     _defaultWallet.AddKey(myKey);
     _blockStore = new MemoryBlockStore(Params);
 }