public static String GetScriptScript(this Contracts.Table value) { List <NBitcoin.PubKey> publicKeys = new List <NBitcoin.PubKey>(); foreach (Models.Peer peer in value.Peers) { NBitcoin.PubKey pubKey = new NBitcoin.PubKey(peer.PublicKey); publicKeys.Add(pubKey); } NBitcoin.Script tableScript = NBitcoin.PayToMultiSigTemplate .Instance .GenerateScriptPubKey(value.MinPlayers, publicKeys.ToArray()); return(tableScript.ToString()); }
public static FileScript ParseScript(NBitcoin.Script script) { var ops = script.ToOps().ToList(); if ( ops.Count < 5 || ops[0].Code != NBitcoin.OpcodeType.OP_RETURN || !Encoding.UTF8.GetBytes(FileScript.Address).SequenceEqual(ops[1].PushData) ) { return(null); } return(new FileScript { Body = ops[2].PushData, MimeType = Encoding.UTF8.GetString(ops[3].PushData), Name = Encoding.UTF8.GetString(ops[4].PushData) }); }
public async Task <Transaction> GetTransaction(string id) { RawTransactionResult tx = await _client.GetRawTransactionAsync(id); if (tx == null) { return(null); } TransactionType transactiontype = GetTransactionType(tx); var transaction = new Transaction { OriginalJson = tx.OriginalJson, TransactionType = transactiontype, Blockhash = tx.Blockhash, TransactionId = tx.Txid, Size = tx.Size, TransactionsIn = new List <Transaction.TransactionIn>(), TransactionsOut = new List <Transaction.TransactionOut>(), Time = tx.GetTime() }; int index = 0; foreach (var input in tx.Input) { var vIn = new Transaction.TransactionIn { Index = index, Coinbase = input.Coinbase, Sequence = input.Sequence, ScriptSigHex = input.ScriptSig?.Hex, AssetId = null, // pointer to previous tx/vout: PrevTxIdPointer = input.Txid, PrevVOutPointer = (int)input.Vout, // we'll try to fetch this id possible PrevVOutFetchedAddress = null, PrevVOutFetchedValue = 0 }; if (input.Txid != null) { // Retrieve the origin address by retrieving the previous transaction and extracting the receive address and value var previousTx = await _client.GetRawTransactionAsync(input.Txid); if (previousTx != null) { var n = input.Vout; vIn.PrevVOutFetchedAddress = previousTx.Output[(int)n].ScriptPubKey.Addresses.First(); vIn.PrevVOutFetchedValue = previousTx.Output[(int)n].Value; } } transaction.TransactionsIn.Add(vIn); } index = 0; foreach (var output in tx.Output) { var vOut = new Transaction.TransactionOut { TransactionId = transaction.TransactionId, Value = output.Value, Quantity = output.Index, AssetId = null, Index = index++, }; if (output.ScriptPubKey.Addresses != null) // Satoshi 14.2 { vOut.Address = output.ScriptPubKey.Addresses.FirstOrDefault(); } else { string hexScript = output.ScriptPubKey.Hex; if (!string.IsNullOrEmpty(hexScript)) { byte[] decodedScript = Encoders.Hex.DecodeData(hexScript); NBitcoin.Script script = new NBitcoin.Script(decodedScript); var pubKey = NBitcoin.PayToPubkeyTemplate.Instance.ExtractScriptPubKeyParameters(script); if (pubKey != null) { NBitcoin.BitcoinPubKeyAddress address = pubKey.GetAddress(NetworkSpecs.Gravium.Main()); vOut.Address = address.ToString(); } else { vOut.Address = script.ToString(); } } else { vOut.Address = output.ScriptPubKey.Type; } } transaction.TransactionsOut.Add(vOut); } return(transaction); }
public void IsSmartContractInternalCall_Failure() { var script = new NBitcoin.Script(new byte[] { 0xFF, (byte)ScOpcodeType.OP_INTERNALCONTRACTTRANSFER, 0xFF }); Assert.False(script.IsSmartContractInternalCall()); }
public void IsSmartContractInternalCall_Success() { var script = new NBitcoin.Script(new byte[] { (byte)ScOpcodeType.OP_INTERNALCONTRACTTRANSFER }); Assert.True(script.IsSmartContractInternalCall()); }
public void IsSmartContractSpend_Failure() { var script = new NBitcoin.Script(new byte[] { 0xFF, (byte)ScOpcodeType.OP_SPEND, 0xFF }); Assert.False(script.IsSmartContractSpend()); }
public void IsSmartContractSpend_Success() { var script = new NBitcoin.Script(new byte[] { (byte)ScOpcodeType.OP_SPEND }); Assert.True(script.IsSmartContractSpend()); }
public void IsSmartContractExec_CallContract_Success() { var script = new NBitcoin.Script(new byte[] { (byte)ScOpcodeType.OP_CALLCONTRACT }); Assert.True(script.IsSmartContractExec()); }
public void IsSmartContractCreate_Failure() { var script = new NBitcoin.Script(new byte[] { 0xFF, (byte)ScOpcodeType.OP_CREATECONTRACT, 0xFF }); Assert.False(script.IsSmartContractCreate()); }
public void IsSmartContractCreate_Success() { var script = new NBitcoin.Script(new byte[] { (byte)ScOpcodeType.OP_CREATECONTRACT }); Assert.True(script.IsSmartContractCreate()); }
public void IsSmartContractExec_CallContract_Failure() { var script = new NBitcoin.Script(new byte[] { 0xFF, (byte)ScOpcodeType.OP_CALLCONTRACT, 0xFF }); Assert.False(script.IsSmartContractExec()); }