// Create a new transaction tx := dcrutil.NewTx() // Add an input to the transaction inputTxHash, _ := chainhash.NewHashFromString("1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef") input := wire.NewOutPoint(inputTxHash, 0) tx.AddTxIn(wire.NewTxIn(input, nil, nil))
// Load the public key from a hex-encoded string pubKeyStr := "02d1f4c6b931d8e3f3672d71f201cd254f925fa8bc37bb96be8fc3c9b6498bba83" pubKeyBytes, _ := hex.DecodeString(pubKeyStr) pubKey, _ := btcec.ParsePubKey(pubKeyBytes, btcec.S256()) // Load the transaction from a hex-encoded string txStr := "0100000001a35633bf3a81b5d0c37e0e870d545c4187409995a6f99c2a19ab8e6ec942efd40000000000ffffffff02d1f4c6b931d8e3f3672d71f201cd254f925fa8bc37bb96be8fc3c9b6498bba8300000000000000000c6a09100c0ee2cdb9af0b1a" txBytes, _ := hex.DecodeString(txStr) msgTx := wire.NewMsgTx(wire.TxVersion) msgTx.Deserialize(bytes.NewReader(txBytes)) // Verify the transaction signature sigStr := "304502210099aa82a87bc0f71cb74c2a1831b60762797738eac1212a9c99f1693ce2d76cec02202010f12c687b7c8ce7a8b0aa0f3a344d83ae8cf1c2dabf6d494b94525f6f049001" sigBytes, _ := hex.DecodeString(sigStr) sig, _ := btcec.ParseDERSignature(sigBytes, btcec.S256()) if !sig.Verify(msgTx.TxIn[0].SignatureScript, pubKey) { log.Fatal("Invalid signature") }Overall, the go github.com/decred/dcrutil Tx package provides useful functionality for working with transactions on the Decred blockchain.