/// <summary> /// A default account service constructor from a given a wallet service. /// </summary> /// <param name="contractService">A service object that manage contract.</param> /// <param name="contract">Current electronic money contract</param> /// <param name="walletService">A service object that manage ledgers</param> /// <param name="db">A LiteDB datastore</param> /// <returns>AccountService object is used to process individual account operation such as balance in one private key and one contract.</returns> internal AccountService(ContractService contractService, WalletContract contract, WalletService walletService, LiteDatabase db) { this.contractService = contractService; this.contract = contract; this.walletService = walletService; this.db = db; byte[] myByte = Encoding.ASCII.GetBytes(contract.ID); var encrypted = NBitcoin.Crypto.Hashes.RIPEMD160(myByte, myByte.Length); var hashID = encrypted.ByteArrayToString(); account = db.GetCollection <Account>($"Account-{hashID}"); }
/// <summary> /// A default constructor of Wallet service. (Need to initialized from a ContractService object.) /// </summary> /// <param name="contract">A wallet contract object</param> /// <param name="contractService">A wallet contract service object</param> /// <param name="db">LiteDB database object</param> /// <param name="userPrivateKey">User's private key</param> /// <param name="api">Insight-based compatible API (>0.4)</param> /// <param name="TransferFee">Fee for token transfer</param> /// <returns>A wallet service is used to obtain all the ledger from the wallet. Private key is used to create the ledger on the user's behalf.</returns> internal WalletService(WalletContract contract, ContractService contractService, LiteDatabase db, BitcoinSecret userPrivateKey, IInsightAPI api, decimal TransferFee) { this.TransferFee = TransferFee; this.userPrivateKey = userPrivateKey; this.contractService = contractService; this.contract = contract; this.api = api; this.db = db; byte[] myByte = Encoding.ASCII.GetBytes(contract.ID); var encrypted = NBitcoin.Crypto.Hashes.RIPEMD160(myByte, myByte.Length); var hashID = encrypted.ByteArrayToString(); ledger = db.GetCollection <Ledger>($"Ledger-{hashID}"); account = db.GetCollection <Account>($"Account-{hashID}"); ownerAddress = new BitcoinPubKeyAddress(contract.OwnerPublicAddress, contractService.MainNetwork); }