public Hash SignAndSendTransaction(PhantasmaKeys keys, byte[] script, string chain, Action <string> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null) { var tx = new Blockchain.Transaction("simnet", chain, script, DateTime.UtcNow + TimeSpan.FromHours(1)); tx.Sign(keys); SendRawTransaction(Base16.Encode(tx.ToByteArray(true)), callback, errorHandlingCallback); return(tx.Hash); }
public IEnumerator SignAndSendTransaction(KeyPair keys, byte[] script, string chain, Action <string> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null) { Debug.Log("Sending transaction..."); var tx = new Blockchain.Transaction("simnet", chain, script, DateTime.UtcNow + TimeSpan.FromHours(1)); tx.Sign(keys); yield return(SendRawTransaction(Base16.Encode(tx.ToByteArray(true)), callback, errorHandlingCallback)); }
public IEnumerator SignAndSendTransactionWithPayload(PhantasmaKeys keys, string nexus, byte[] script, string chain, byte[] payload, Action <string> callback, Action <EPHANTASMA_SDK_ERROR_TYPE, string> errorHandlingCallback = null) { Debug.Log("Sending transaction..."); var tx = new Blockchain.Transaction(nexus, chain, script, DateTime.UtcNow + TimeSpan.FromMinutes(20), payload); tx.Sign(keys); yield return(SendRawTransaction(Base16.Encode(tx.ToByteArray(true)), callback, errorHandlingCallback)); }
private Hash SettleTransaction(string sourcePlatform, string chain, Hash txHash) { var script = new ScriptBuilder(). AllowGas(SwapKeys.Address, Address.Null, MinimumFee, 9999). CallContract("interop", nameof(InteropContract.SettleTransaction), SwapKeys.Address, sourcePlatform, chain, txHash). SpendGas(SwapKeys.Address). EndScript(); var tx = new Blockchain.Transaction(Nexus.Name, "main", script, Timestamp.Now + TimeSpan.FromMinutes(5), CLI.Identifier); tx.Sign(SwapKeys); var bytes = tx.ToByteArray(true); var txData = Base16.Encode(bytes); var result = this.NexusAPI.SendRawTransaction(txData); if (result is SingleResult) { return(tx.Hash); } return(Hash.Null); }
public static Hash ExecuteTransaction(SpookSettings settings, NexusAPI api, byte[] script, ProofOfWork proofOfWork, params IKeyPair[] keys) { var tx = new Blockchain.Transaction(settings.Node.NexusName, DomainSettings.RootChainName, script, Timestamp.Now + TimeSpan.FromMinutes(5), Spook.TxIdentifier); if (proofOfWork != ProofOfWork.None) { logger.Message($"Mining proof of work with difficulty: {proofOfWork}..."); tx.Mine(proofOfWork); } logger.Message("Signing message..."); foreach (var keyPair in keys) { tx.Sign(keyPair); } var rawTx = tx.ToByteArray(true); var encodedRawTx = Base16.Encode(rawTx); try { api.Execute("sendRawTransaction", new[] { encodedRawTx }); } catch (Exception e) { throw new CommandException(e.Message); } Thread.Sleep(4000); var hash = tx.Hash.ToString(); do { var resultStr = api.Execute("getTransaction", new[] { hash }); dynamic result = JsonConvert.DeserializeObject <TransactionResult>(resultStr); if (result is TransactionResult) { _transactionResults[hash] = (TransactionResult)result; } else if (result is ErrorResult) { var temp = (ErrorResult)result; if (temp.error.Contains("pending")) { Thread.Sleep(1000); continue; } else { throw new CommandException(temp.error); } } else { throw new Exception("Something weird happened with transaction " + hash); } break; } while (true); logger.Success($"Sent transaction with hash {hash}!"); return(Hash.Parse(hash)); }
private static Hash ExecuteTransaction(NexusAPI api, byte[] script, ProofOfWork proofOfWork, params IKeyPair[] keys) { var tx = new Blockchain.Transaction(api.Nexus.Name, DomainSettings.RootChainName, script, Timestamp.Now + TimeSpan.FromMinutes(5), CLI.Identifier); if (proofOfWork != ProofOfWork.None) { logger.Message($"Mining proof of work with difficulty: {proofOfWork}..."); tx.Mine(proofOfWork); } logger.Message("Signing message..."); foreach (var keyPair in keys) { tx.Sign(keyPair); } var rawTx = tx.ToByteArray(true); try { api.SendRawTransaction(Base16.Encode(rawTx)); } catch (Exception e) { throw new CommandException(e.Message); } Thread.Sleep(3000); var hash = tx.Hash.ToString(); do { try { var result = api.GetTransaction(hash); } catch (Exception e) { throw new CommandException(e.Message); } /*if (result is ErrorResult) * { * var temp = (ErrorResult)result; * if (temp.error.Contains("pending")) * { * Thread.Sleep(1000); * } * else * { * throw new CommandException(temp.error); * } * } * else*/ { break; } } while (true); logger.Success($"Sent transaction with hash {hash}!"); return(Hash.Parse(hash)); }