private void CheckStatus(TxResponse txResponse) { Thread.Sleep(500); masterNodeApi.CheckTransaction(txUri, txResponse.hash, (bool success, string json) => { if (success) { CheckTransactionData checkTransactionData = JsonUtility.FromJson <CheckTransactionData>(json); var n = JSON.Parse(json); checkTransactionData.state = n["state"]; txResponse.transactionData = checkTransactionData; txResponse.transactionData.transaction.payload.kwargs = n["transaction"]["payload"]["kwargs"]; if (checkTransactionData.status == 0) { onCompleteAction(TransactionStatus.Completed, txResponse); } else { txResponse.error = txResponse.transactionData.result; onCompleteAction(TransactionStatus.Error, txResponse); } return; } if (checkStatusAttempts-- > 0) { CheckStatus(txResponse); } else { TxError("Failed to check status of the transaction."); } }); }
private void SendTransaction() { string payloadJson = JsonUtility.ToJson(txData.payload); string kwargs = txInfo.getKwargString(); payloadJson = payloadJson.Replace(replaceString, kwargs); txData.metadata.signature = txInfo.sender.GetSignatureString(payloadJson); Debug.Log($"sig: {txData.metadata.signature}\n\npayload: {payloadJson}"); txData.metadata.timestamp = Helper.GetDateStamp(); string txDataJson = JsonUtility.ToJson(txData).Replace(replaceString, kwargs); Debug.Log($"Sending txData Json data: {txDataJson}"); masterNodeApi.SendTransaction(txUri, txDataJson, (bool success, string result) => { Debug.Log($"SendTransaction result was {success}: {result}"); TxResponse txResponse = JsonUtility.FromJson <TxResponse>(result); if (!success || result.Contains("error")) { onCompleteAction(TransactionStatus.Error, txResponse); } else { onCompleteAction(TransactionStatus.SubmittedProcessing, txResponse); CheckStatus(txResponse); } }); }
void TxError(string error) { Debug.LogError(error); TxResponse txResponse = new TxResponse(); txResponse.error = error; onCompleteAction(TransactionStatus.Error, txResponse); }