/// <summary> /// The method is used to broadcast the transaction over the blockchain using the account of the user /// </summary> /// <param name="contentdata">the transaction generated by the operations</param> /// <param name="privateKey">private key of the user</param> /// <typeparam name="T">type of the transaction's json body</typeparam> /// <returns> transaction response data</returns> protected TransactionResponse StartBroadcasting <T>(T contentdata, string privateKey) { var trans = new Transaction(Config); var key = new Key(Config); TransactionResponse finalResponse; try { //ask for token symbol each time a transaction is performed //todo:next build append a parameter as "CurrencySymbol" in each transaction functions to calculate the charges. var fees = trans.CalculateFee(contentdata, "SPHTX"); var feeAddedOperation = trans.AddFee(contentdata, fees.result); var transresponse = trans.CreateSimpleTransaction(feeAddedOperation.Result); if (transresponse == null) { return(null); } var aboutresponse = trans.About(); if (aboutresponse == null) { return(null); } var transaction = JsonConvert.SerializeObject(transresponse.Result); var digest = key.GetTransactionDigestServer(transresponse); var signature = key.SignDigest(digest.result, privateKey, new byte[130]); var response = key.AddSignatureServer(transresponse, signature); finalResponse = trans.BroadcastTransaction(response); } catch (Exception ex) { _logger.WriteError($"Message:{ex.Message} | StackTrace:{ex.StackTrace}"); throw; } return(finalResponse); }
/// <summary> /// Client Constructor /// </summary> /// <param name="hostname">the rpc endpoint ip address</param> /// <param name="daemonPort">the daemon rpc endpoint post</param> /// <param name="walletPort">the wallet rpc endpoint post</param> public SophiaClient(string hostname = "", ushort daemonPort = 0, ushort walletPort = 0) { var config = LoadJson <Config>("config.json"); if (config == null) { return; } if (hostname != "") { config.Hostname = hostname; } if (daemonPort != 0) { config.DaemonPort = daemonPort; } if (walletPort != 0) { config.WalletPort = walletPort; } Account = new Account(config); Asset = new Asset(config); Key = new Key(config); Transaction = new Transaction(config); Witness = new Witness(config); Data = new Data(config); Application = new Application(config); var aboutResponse = Transaction.About(); if (aboutResponse != null) { RpcConnection.ChainId = aboutResponse.Result.ChainId; } }