mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-25 08:16:46 +00:00

* '' * '' * '' * Changes genesis block version to 0. * a * a * All tests are done. * All tests passed for changed block version from int32 to uint16 * Adds validation of rejecting blocks with unknown versions. * Changes txn version from int32 to uint16. * . * Adds comments to exported functions. * Change functions name from ConvertFromRpcScriptPubKeyToRPCScriptPubKey to ConvertFromAppMsgRPCScriptPubKeyToRPCScriptPubKey and from ConvertFromRPCScriptPubKeyToRpcScriptPubKey to ConvertFromRPCScriptPubKeyToAppMsgRPCScriptPubKey * change comment to "ScriptPublicKey represents a Kaspad ScriptPublicKey" * delete part (tx.Version < 0) that cannot be exist on the if statement. * Revert protobuf version. * Fix a comment. * Fix a comment. * Rename a variable. * Rename a variable. * Remove a const. * Rename a type. * Rename a field. * Rename a field. * Remove commented-out code. * Remove dangerous nil case in DomainTransactionOutput.Clone(). * Remove a constant. * Fix a string. * Fix wrong totalScriptPubKeySize in transactionMassStandalonePart. * Remove a constant. * Remove an unused error. * Fix a serialization error. * Specify version types to be uint16 explicitly. * Use constants.ScriptPublicKeyVersion. * Fix a bad test. * Remove some whitespace. * Add a case to utxoEntry.Equal(). * Rename scriptPubKey to scriptPublicKey. * Remove a TODO. * Rename constants. * Rename a variable. * Add version to parseShortForm. Co-authored-by: tal <tal@daglabs.com> Co-authored-by: stasatdaglabs <stas@daglabs.com>
80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
// Copyright (c) 2014-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package txscript_test
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"fmt"
|
|
"github.com/kaspanet/kaspad/domain/consensus/model/externalapi"
|
|
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/txscript"
|
|
"github.com/kaspanet/kaspad/domain/dagconfig"
|
|
"github.com/kaspanet/kaspad/util"
|
|
)
|
|
|
|
// This example demonstrates creating a script which pays to a kaspa address.
|
|
// It also prints the created script hex and uses the DisasmString function to
|
|
// display the disassembled script.
|
|
func ExamplePayToAddrScript() {
|
|
// Parse the address to send the coins to into a util.Address
|
|
// which is useful to ensure the accuracy of the address and determine
|
|
// the address type. It is also required for the upcoming call to
|
|
// PayToAddrScript.
|
|
addressStr := "kaspa:qqfgqp8l9l90zwetj84k2jcac2m8falvvyy8xjtnhd"
|
|
address, err := util.DecodeAddress(addressStr, util.Bech32PrefixKaspa)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
// Create a public key script that pays to the address.
|
|
script, err := txscript.PayToAddrScript(address)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Printf("Script Hex: %x\n", script.Script)
|
|
|
|
disasm, err := txscript.DisasmString(script.Version, script.Script)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Println("Script Disassembly:", disasm)
|
|
|
|
// Output:
|
|
// Script Hex: 76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac
|
|
// Script Disassembly: OP_DUP OP_HASH160 128004ff2fcaf13b2b91eb654b1dc2b674f7ec61 OP_EQUALVERIFY OP_CHECKSIG
|
|
}
|
|
|
|
// This example demonstrates extracting information from a standard public key
|
|
// script.
|
|
func ExampleExtractScriptPubKeyAddress() {
|
|
// Start with a standard pay-to-pubkey-hash script.
|
|
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
|
|
script, err := hex.DecodeString(scriptHex)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
// Extract and print details from the script.
|
|
scriptClass, address, err := txscript.ExtractScriptPubKeyAddress(
|
|
&externalapi.ScriptPublicKey{
|
|
Script: script,
|
|
Version: 0,
|
|
}, &dagconfig.MainnetParams)
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Println("Script Class:", scriptClass)
|
|
fmt.Println("Address:", address)
|
|
|
|
// Output:
|
|
// Script Class: pubkeyhash
|
|
// Address: kaspa:qqfgqp8l9l90zwetj84k2jcac2m8falvvyy8xjtnhd
|
|
}
|