private void ProcessInvokeWithWallet(JObject result, Signers signers = null) { Transaction tx = null; if (wallet != null && signers != null) { UInt160[] accounts = wallet.GetAccounts().Where(p => !p.Lock && !p.WatchOnly).Select(p => p.ScriptHash).ToArray(); Signer[] witnessCosigners = signers.GetSigners().Where(p => accounts.Contains(p.Account)).ToArray(); if (witnessCosigners.Count() > 0) { tx = wallet.MakeTransaction(result["script"].AsString().HexToBytes(), null, witnessCosigners); ContractParametersContext context = new ContractParametersContext(tx); wallet.Sign(context); if (context.Completed) { tx.Witnesses = context.GetWitnesses(); } else { tx = null; } } } result["tx"] = tx?.ToArray().ToHexString(); }
protected virtual JObject GetRawTransaction(JArray _params) { UInt256 hash = UInt256.Parse(_params[0].AsString()); bool verbose = _params.Count >= 2 && _params[1].AsBoolean(); Transaction tx = Blockchain.Singleton.GetTransaction(hash); if (tx == null) { throw new RpcException(-100, "Unknown transaction"); } if (verbose) { JObject json = Utility.TransactionToJson(tx); TransactionState txState = Blockchain.Singleton.View.Transactions.TryGet(hash); if (txState != null) { Header header = Blockchain.Singleton.GetHeader(txState.BlockIndex); json["blockhash"] = header.Hash.ToString(); json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1; json["blocktime"] = header.Timestamp; json["vmstate"] = txState.VMState; } return(json); } return(Convert.ToBase64String(tx.ToArray())); }
public IActionResult GetRawTransaction(string txid, bool verbose = false) { UInt256 hash = UInt256.Parse(txid); Transaction tx = Blockchain.Singleton.GetTransaction(hash); if (tx == null) { throw new RestException(-100, "Unknown transaction"); } if (verbose) { JObject json = tx.ToJson(); TransactionState txState = Blockchain.Singleton.View.Transactions.TryGet(hash); if (txState != null) { Header header = Blockchain.Singleton.GetHeader(txState.BlockIndex); json["blockhash"] = header.Hash.ToString(); json["confirmations"] = Blockchain.Singleton.Height - header.Index + 1; json["blocktime"] = header.Timestamp; json["vmState"] = txState.VMState; } return(FormatJson(json)); } return(FormatJson(tx.ToArray().ToHexString())); }
private void ProcessInvokeWithWallet(JObject result, Signers signers = null) { Transaction tx = null; if (wallet != null && signers != null) { Signer[] witnessSigners = signers.GetSigners().ToArray(); UInt160 sender = signers.Size > 0 ? signers.GetSigners()[0].Account : null; if (witnessSigners.Count() > 0) { try { tx = wallet.MakeTransaction(result["script"].AsString().HexToBytes(), sender, witnessSigners); } catch (Exception e) { result["exception"] = GetExceptionMessage(e); return; } ContractParametersContext context = new ContractParametersContext(tx); wallet.Sign(context); if (context.Completed) { tx.Witnesses = context.GetWitnesses(); } else { tx = null; } } } result["tx"] = tx?.ToArray().ToHexString(); }
private void ProcessInvoke(JObject result) { if (Wallet != null) { Transaction tx = Wallet.MakeTransaction(result["script"].AsString().HexToBytes()); ContractParametersContext context = new ContractParametersContext(tx); Wallet.Sign(context); if (context.Completed) { tx.Witnesses = context.GetWitnesses(); } else { tx = null; } result["tx"] = tx?.ToArray().ToHexString(); } }
private void ProcessInvokeWithWallet(JObject result, UInt160 sender = null, Signers signers = null) { Transaction tx = null; if (wallet != null && signers != null) { Signer[] witnessSigners = signers.GetSigners().ToArray(); UInt160[] signersAccounts = signers.GetScriptHashesForVerifying(null); if (sender != null) { if (!signersAccounts.Contains(sender)) { witnessSigners = witnessSigners.Prepend(new Signer() { Account = sender, Scopes = WitnessScope.CalledByEntry }).ToArray(); } else if (signersAccounts[0] != sender) { throw new RpcException(-32602, "The sender must be the first element of signers."); } } if (witnessSigners.Count() > 0) { tx = wallet.MakeTransaction(Convert.FromBase64String(result["script"].AsString()), sender, witnessSigners); ContractParametersContext context = new ContractParametersContext(tx); wallet.Sign(context); if (context.Completed) { tx.Witnesses = context.GetWitnesses(); } else { tx = null; } } } result["tx"] = tx?.ToArray().ToHexString(); }