コード例 #1
0
        /// <summary>
        /// Initializes the cross-chain transfer tests.
        /// </summary>
        /// <param name="network">The network to run the tests for.</param>
        public CrossChainTestBase(Network network = null)
        {
            this.network = network ?? FederatedPegNetwork.NetworksSelector.Regtest();
            NetworkRegistration.Register(this.network);

            this.loggerFactory    = Substitute.For <ILoggerFactory>();
            this.logger           = Substitute.For <ILogger>();
            this.asyncLoopFactory = new AsyncLoopFactory(this.loggerFactory);
            this.loggerFactory.CreateLogger(null).ReturnsForAnyArgs(this.logger);
            this.dateTimeProvider                   = DateTimeProvider.Default;
            this.opReturnDataReader                 = new OpReturnDataReader(this.loggerFactory, this.network);
            this.blockRepository                    = Substitute.For <IBlockRepository>();
            this.fullNode                           = Substitute.For <IFullNode>();
            this.withdrawalTransactionBuilder       = Substitute.For <IWithdrawalTransactionBuilder>();
            this.federationWalletManager            = Substitute.For <IFederationWalletManager>();
            this.federationWalletSyncManager        = Substitute.For <IFederationWalletSyncManager>();
            this.FederationWalletTransactionBuilder = Substitute.For <IFederationWalletTransactionBuilder>();
            this.walletFeePolicy                    = Substitute.For <IWalletFeePolicy>();
            this.nodeLifetime                       = new NodeLifetime();
            this.connectionManager                  = Substitute.For <IConnectionManager>();
            this.dBreezeSerializer                  = new DBreezeSerializer(this.network);

            this.wallet = null;
            this.federationGatewaySettings = Substitute.For <IFederationGatewaySettings>();
            this.chain = new ConcurrentChain(this.network);

            this.federationGatewaySettings.MinCoinMaturity.Returns(1);
            this.federationGatewaySettings.TransactionFee.Returns(new Money(0.01m, MoneyUnit.BTC));

            // Generate the keys used by the federation members for our tests.
            this.federationKeys = new[]
            {
                "ensure feel swift crucial bridge charge cloud tell hobby twenty people mandate",
                "quiz sunset vote alley draw turkey hill scrap lumber game differ fiction",
                "exchange rent bronze pole post hurry oppose drama eternal voice client state"
            }.Select(m => HdOperations.GetExtendedKey(m)).ToArray();

            SetExtendedKey(0);

            this.fundingTransactions = new List <Transaction>();

            this.blockDict = new Dictionary <uint256, Block>();
            this.blockDict[this.network.GenesisHash] = this.network.GetGenesis();

            this.blockRepository.GetBlocksAsync(Arg.Any <List <uint256> >()).ReturnsForAnyArgs((x) => {
                var hashes = x.ArgAt <List <uint256> >(0);
                var blocks = new List <Block>();
                for (int i = 0; i < hashes.Count; i++)
                {
                    blocks.Add(this.blockDict.TryGetValue(hashes[i], out Block block) ? block : null);
                }

                return(blocks);
            });
        }
コード例 #2
0
 public WithdrawalTransactionBuilder(
     ILoggerFactory loggerFactory,
     Network network,
     IFederationWalletManager federationWalletManager,
     IFederationWalletTransactionBuilder federationWalletTransactionBuilder,
     IFederationGatewaySettings federationGatewaySettings)
 {
     this.logger  = loggerFactory.CreateLogger(this.GetType().FullName);
     this.network = network;
     this.federationWalletManager            = federationWalletManager;
     this.federationWalletTransactionBuilder = federationWalletTransactionBuilder;
     this.federationGatewaySettings          = federationGatewaySettings;
 }
コード例 #3
0
        /// <summary>
        /// Create the wallet manager and wallet transaction handler.
        /// </summary>
        /// <param name="dataFolder">The data folder.</param>
        protected void Init(DataFolder dataFolder)
        {
            this.dataFolder = dataFolder;

            // Create the wallet manager.
            this.federationWalletManager = new FederationWalletManager(
                this.loggerFactory,
                this.network,
                this.ChainIndexer,
                dataFolder,
                this.walletFeePolicy,
                this.asyncLoopFactory,
                new NodeLifetime(),
                this.dateTimeProvider,
                this.federationGatewaySettings,
                this.withdrawalExtractor);

            // Starts and creates the wallet.
            this.federationWalletManager.Start();
            this.wallet = this.federationWalletManager.GetWallet();

            // TODO: The transaction builder, cross-chain store and fed wallet tx handler should be tested individually.
            this.FederationWalletTransactionBuilder = new FederationWalletTransactionBuilder(this.loggerFactory, this.federationWalletManager, this.walletFeePolicy, this.network);
            this.withdrawalTransactionBuilder       = new WithdrawalTransactionBuilder(this.loggerFactory, this.network, this.federationWalletManager, this.FederationWalletTransactionBuilder, this.federationGatewaySettings);

            var storeSettings = (StoreSettings)FormatterServices.GetUninitializedObject(typeof(StoreSettings));

            this.federationWalletSyncManager = new FederationWalletSyncManager(this.loggerFactory, this.federationWalletManager, this.ChainIndexer, this.network,
                                                                               this.blockRepository, storeSettings, Substitute.For <INodeLifetime>());

            this.federationWalletSyncManager.Initialize();

            // Set up the encrypted seed on the wallet.
            string encryptedSeed = this.extendedKey.PrivateKey.GetEncryptedBitcoinSecret(walletPassword, this.network).ToWif();

            this.wallet.EncryptedSeed = encryptedSeed;

            this.federationWalletManager.Secret = new WalletSecret()
            {
                WalletPassword = walletPassword
            };

            System.Reflection.FieldInfo prop = this.federationWalletManager.GetType().GetField("isFederationActive",
                                                                                               System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            prop.SetValue(this.federationWalletManager, true);
        }