private bool SendTxCreateToken(string symbol, string name, long totalSupply, short decimals, string owner, string privateKey) { try { TransactionCreateTokenRequest data = new TransactionCreateTokenRequest(); data.Body = new TransactionCreateTokenRequestBody(); data.Body.Nonce = DateTimeUtility.CurrentUnixTimeUTC(); data.Body.Fee = "0"; data.Body.Symbol = symbol; data.Body.Name = name; data.Body.TotalSupply = totalSupply; data.Body.Decimals = decimals; data.Body.Owner = owner; data.Signature = KeySignature.Sign(privateKey, JsonConvert.SerializeObject(data.Body)); string endpoint = nodeServerAddress + "/transaction/create-token"; Log("Api:" + endpoint); string responseData = this.SendPostRequest(endpoint, JsonConvert.SerializeObject(data)); Log("Response:" + responseData); return(true); } catch (Exception ex) { Log("Failed: " + ex.Message); return(false); } }
// POST: /transaction/create-token public static HttpResponse AddToken(HttpRequest request) { TransactionCreateTokenRequest requestData = JsonConvert.DeserializeObject <TransactionCreateTokenRequest>(request.Content); TransactionController controller = new TransactionController(); var response = controller.CreateToken(requestData); Echo(request); return(CreateHttpResponse(response)); }
public GenericResponse CreateToken(TransactionCreateTokenRequest value) { try { VerifySignature(value.Body, value.Signature, value.Body.Owner); if (!ApplicationState.IsChainUpToDate) { return(new GenericResponse(null, ResponseCodes.Success, ResponseMessages.NodeNotConsensusReady)); } //Perform transaction TransactionServices transactionService = new TransactionServices(); string txId = transactionService.AddToken( value.Body.Nonce, Convert.ToDecimal(value.Body.Fee), value.Body.Symbol, value.Body.Name, value.Body.TotalSupply, value.Body.Decimals, value.Body.Owner); ApplicationLog.Info("Transaction added to queue for next block. TxId: " + txId); return(new GenericResponse(txId, ResponseCodes.Success, "Transaction added to queue for next block.")); } catch (ValidationException vex) { ApplicationLog.Warn("ValidationException [" + vex.Code + "]: " + vex.Message); return(new GenericResponse(null, vex.Code, vex.Message)); } catch (Exception ex) { ApplicationLog.Exception(ex); return(new GenericResponse(null, ResponseCodes.Error, ResponseMessages.Error)); } }