Example #1
0
        /// <summary>
        /// Creates default fungible currency consolidator.
        /// WARNING: Consolidator does not check if utxos are fungible. Make sure to pass only valid currencies.
        /// </summary>
        /// <param name="_plasmaAPIService">plasma API service</param>
        /// <param name="_txEncoder">transaction encoder</param>
        /// <param name="_owner">consolidation requester address</param>
        /// <param name="_currency">consolidation currency</param>
        /// <param name="_utxos">array of utxo data for consolidation</param>
        /// <param name="_amount">amount to consolidate (optional, if null or greater than balance consolidate all utxos)</param>
        public FCConsolidator(PlasmaAPIService _plasmaAPIService, ITransactionEncoder _txEncoder, string _owner, string _currency, UTXOData[] _utxos, BigInteger?_amount = null)
        {
            Transactions     = new List <Transaction>();
            MergedUtxo       = null;
            plasmaAPIService = _plasmaAPIService;
            owner            = _owner;
            currency         = _currency;
            txEncoder        = _txEncoder;

            BigInteger balance = BigInteger.Zero;

            Array.Sort(_utxos, (x, y) => x.Data.CompareTo(x.Data));
            foreach (var utxo in _utxos)
            {
                if ((utxo.Owner == owner) && (utxo.Currency == _currency))
                {
                    utxoList.Add(utxo);
                    balance += utxo.Data;
                    if (_amount.HasValue && balance >= _amount.Value)
                    {
                        break;
                    }
                }
            }

            amount = (_amount.HasValue && balance >= _amount.Value) ? _amount.Value : balance;

            PrepareTransactions();
        }
Example #2
0
        /// <summary>
        /// Creates PlasmaComm object.
        /// </summary>
        /// <param name="ethClient">Ethereum jsonRpc client implementation</param>
        /// <param name="gameCenterContract">game center contract address</param>
        /// <param name="watcherClient">watcher client</param>
        /// <param name="childChainClient">child chain client</param>
        /// <param name="rootChainAddress">root chain address</param>
        /// <param name="_rootChainVersion">root chain version</param>
        public PlasmaComm(Nethereum.JsonRpc.Client.IClient ethClient,
                          string gameCenterContract,
                          PlasmaCore.RPC.IClient watcherClient,
                          PlasmaCore.RPC.IClient childChainClient,
                          string rootChainAddress,
                          RootChainVersion _rootChainVersion)
        {
            web3   = new Web3(ethClient);
            bcComm = new BCComm(ethClient, gameCenterContract);

            plasmaApiService = new PlasmaAPIService(watcherClient, childChainClient);
            rootChainVersion = _rootChainVersion;

            if (rootChainAddress == null)
            {
                var statusData = plasmaApiService.GetStatus().Result;
                rootChainAddress = statusData.ContractAddr;
            }

            if (rootChainAddress != null)
            {
                rootChainContract = new RootChainContract(web3, rootChainAddress, rootChainVersion);
            }

            transactionEncoder = TransactionEncoderFactory.Create(rootChainVersion, rootChainAddress);
        }
 public TransactionBuilderTests(MockupPlasmaAPIServiceFixture plasmaAPIServiceFixture)
 {
     PlasmaAPIService = plasmaAPIServiceFixture.PlasmaAPIService;
 }
Example #4
0
 public AccountTests(MockupPlasmaAPIServiceFixture plasmaAPIServiceFixture)
 {
     PlasmaAPIService = plasmaAPIServiceFixture.PlasmaAPIService;
 }
 public MockupPlasmaAPIServiceFixture()
 {
     PlasmaAPIService = new PlasmaAPIService(new MockupRPCClient(), new MockupRPCClient());
 }
 public ConsolidatorTests(MockupPlasmaAPIServiceFixture plasmaAPIServiceFixture)
 {
     PlasmaAPIService = plasmaAPIServiceFixture.PlasmaAPIService;
 }