/// <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(); }
public RpcFactory( Network network, Uri server, RPCCredentialString credential, ITransactionEncoder exodusEncoder) { if (network == null) { throw new ArgumentNullException(nameof(network)); } if (server == null) { throw new ArgumentNullException(nameof(server)); } if (credential == null) { throw new ArgumentNullException(nameof(credential)); } if (exodusEncoder == null) { throw new ArgumentNullException(nameof(exodusEncoder)); } Network = network; this.serverUri = server; this.credential = credential; ExodusEncoder = exodusEncoder; GenesisTransactions = new HashSet <uint256>(Network.GetGenesis().Transactions.Select(t => t.GetHash())); }
/// <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 static string Sign(ITransactionEncoder txEncoder, Transaction transaction, string address, string privateKey) { byte[] encodedTx = txEncoder.EncodeRaw(transaction); var rawHash = new Sha3Keccack().CalculateHash(encodedTx); var ecKey = new Nethereum.Signer.EthECKey(privateKey); var ecdsaSignature = ecKey.SignAndCalculateV(rawHash); string signature = Nethereum.Signer.EthECDSASignature.CreateStringSignature(ecdsaSignature); transaction.SetSignature(address, signature.HexToByteArray()); return(txEncoder.EncodeSigned(transaction).ToHex(true)); }
public BlocksStorage(IConfiguration config, IMainDatabaseFactory db, ITransactionEncoder exodusEncoder) { if (config == null) { throw new ArgumentNullException(nameof(config)); } if (db == null) { throw new ArgumentNullException(nameof(db)); } if (exodusEncoder == null) { throw new ArgumentNullException(nameof(exodusEncoder)); } this.db = db; this.zcoinNetwork = ZcoinNetworks.Instance.GetNetwork(config.GetZcoinSection().Network.Type); this.exodusEncoder = exodusEncoder; }