{"modulePath":"github.com/unpackdev/solgo","version":"v0.3.7","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package bytecode\n\nPackage bytecode provides tools for decoding and analyzing Ethereum contract, transaction, events, and log bytecode. The package is designed to extract and interpret metadata from Ethereum contract creation bytecode. It provides a Metadata struct that represents the metadata contained in the bytecode, as defined by the Solidity compiler. This includes information such as the IPFS hash of the metadata, the Swarm hash of the metadata, experimental metadata, and the version of the Solidity compiler used.\n\n## Types\n\n```go\ntype Argument struct {\n\tName    string `json:\"name\"`    // Name of the argument\n\tType    string `json:\"type\"`    // Type of the argument\n\tValue   string `json:\"value\"`   // Value of the argument\n\tIndexed bool   `json:\"indexed\"` // Indicates if the argument is indexed\n}\n```\nArgument represents a single argument in a contract constructor. It includes the argument's name, type, value, and whether it is indexed.\n\n```go\ntype Constructor struct {\n\tAbi               string        `json:\"abi\"`                // ABI of the constructor\n\tParsed            abi.ABI       `json:\"-\"`                  // Parsed ABI of the constructor\n\tSignatureRaw      string        `json:\"signature_raw\"`      // Raw signature of the constructor\n\tArguments         []Argument    `json:\"arguments\"`          // List of arguments in the constructor\n\tUnpackedArguments []interface{} `json:\"unpacked_arguments\"` // List of unpacked arguments in the constructor\n}\n```\nConstructor represents a contract constructor. It includes the ABI of the constructor, the raw signature, and the arguments.\n\n```go\nfunc DecodeConstructorFromAbi(bytecode []byte, constructorAbi string) (*Constructor, error)\n```\nDecodeConstructorFromAbi decodes the constructor from the provided ABI and bytecode. It returns a Constructor object and an error if any occurred during the decoding process.\n\nThe function first checks if the bytecode is empty or does not start with '\\['. If so, it prepends '\\[' to the constructorAbi. Then it attempts to parse the ABI using the abi.JSON function from the go-ethereum library. If the ABI parsing is successful, it unpacks the values from the bytecode using the UnpackValues function. It then checks if the number of unpacked values matches the number of inputs in the constructor. If they match, it creates an Argument object for each input and adds it to the arguments slice. Finally, it returns a Constructor object containing the ABI, raw signature, and arguments.\n\n```go\nfunc (c *Constructor) Pack() ([]byte, error)\n```\nPack packs the arguments in the constructor into a byte slice for future use and verification.\n\n```go\ntype Log struct {\n\tEvent        *abi.Event         `json:\"-\"`             // ABI definition of the log's event.\n\tAddress      common.Address     `json:\"address\"`       // Address of the contract that emitted the event.\n\tAbi          string             `json:\"abi\"`           // ABI string of the event.\n\tSignatureHex common.Hash        `json:\"signature_hex\"` // Hex-encoded signature of the event.\n\tSignature    string             `json:\"signature\"`     // Signature of the event.\n\tType         utils.LogEventType `json:\"type\"`          // Type of the event, classified by solgo.\n\tName         string             `json:\"name\"`          // Name of the event.\n\tData         map[string]any     `json:\"data\"`          // Decoded event data.\n\tTopics       []Topic            `json:\"topics\"`        // Decoded topics of the event.\n}\n```\nLog encapsulates a decoded Ethereum event log. It includes the event's details such as its name, signature, the contract that emitted the event, and the decoded data and topics.\n\n```go\nfunc DecodeLogFromAbi(log *types.Log, abiData []byte) (*Log, error)\n```\nDecodeLogFromAbi decodes an Ethereum event log using the provided ABI data. It returns a Log instance containing the decoded event name, data, and topics. The function requires the event log and its ABI as inputs. It handles errors such as missing topics or failure to parse the ABI.\n\n```go\ntype Metadata struct {\n\tIpfs         []byte      `cbor:\"ipfs\"`         // The IPFS hash of the metadata, if present\n\tBzzr1        []byte      `cbor:\"bzzr1\"`        // The Swarm hash of the metadata, if present (version 1)\n\tBzzr0        []byte      `cbor:\"bzzr0\"`        // The Swarm hash of the metadata, if present (version 0)\n\tExperimental interface{} `cbor:\"experimental\"` // Experimental metadata, if present\n\tSolc         []byte      `cbor:\"solc\"`         // The version of the Solidity compiler used\n\t// contains filtered or unexported fields\n}\n```\nMetadata represents the metadata contained in Ethereum contract creation bytecode. The structure and encoding of the metadata is defined by the Solidity compiler. More information can be found at [https://docs.soliditylang.org/en/v0.8.20/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode](https://docs.soliditylang.org/en/v0.8.20/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode)\n\n```go\nfunc DecodeContractMetadata(bytecode []byte) (*Metadata, error)\n```\nDecodeContractMetadata decodes the metadata from Ethereum contract creation bytecode. It returns a Metadata object and an error, if any occurred during decoding.\n\n```go\nfunc (m *Metadata) AuxFound(b []byte) bool\n```\nAuxFound returns whether the CBOR metadata bytes are contained in the provided byte slice. This is used to verify if contract extracted cbor metadata can be found in the deployed/execution contract bytecode.\n\n```go\nfunc (m *Metadata) GetAuxBytecode() []byte\n```\nGetAuxBytecode returns the raw CBOR metadata of the contract.\n\n```go\nfunc (m *Metadata) GetBzzr0() string\n```\nGetBzzr0 returns the Swarm (version 0) hash of the contract's metadata, if present.\n\n```go\nfunc (m *Metadata) GetBzzr1() string\n```\nGetBzzr1 returns the Swarm (version 1) hash of the contract's metadata, if present.\n\n```go\nfunc (m *Metadata) GetCborLength() int16\n```\nGetCborLength returns the length of the CBOR metadata.\n\n```go\nfunc (m *Metadata) GetCompilerVersion() string\n```\nGetCompilerVersion returns the version of the Solidity compiler used to compile the contract.\n\n```go\nfunc (m *Metadata) GetExecutionBytecode() []byte\n```\nGetExecutionBytecode returns the execution bytecode of the contract.\n\n```go\nfunc (m *Metadata) GetExperimental() bool\n```\nGetExperimental returns whether the contract includes experimental metadata.\n\n```go\nfunc (m *Metadata) GetIPFS() string\n```\nGetIPFS returns the IPFS hash of the contract's metadata, if present.\n\n```go\nfunc (m *Metadata) GetUrls() []string\n```\nGetUrls returns the URLs of the contract's metadata.\n\n```go\nfunc (m *Metadata) IsPartial() bool\n```\nIsPartial checks whenever decoded bytecode data is partial (some fields are missing, not known)\n\n```go\nfunc (m *Metadata) ToProto() *metadata_pb.BytecodeMetadata\n```\nToProto converts the Metadata instance into a protobuf representation, suitable for serialization and transmission across different systems or networks.\n\n```go\ntype Topic struct {\n\tName  string `json:\"name\"`  // The name of the topic.\n\tValue any    `json:\"value\"` // The value of the topic, decoded into the appropriate Go data type.\n}\n```\nTopic represents a single decoded topic from an Ethereum event log. Topics are attributes of an event, such as the method signature and indexed parameters.\n\n```go\nfunc GetTopicByName(name string, topics []Topic) *Topic\n```\nGetTopicByName searches for and returns a Topic by its name from a slice of Topic instances. It facilitates accessing specific topics directly by name rather than iterating over the slice. If the topic is not found, it returns nil.\n\n```go\ntype Transaction struct {\n\tAbi            string                      `json:\"abi\"`             // ABI string of the transaction's method.\n\tSignatureBytes []byte                      `json:\"signature_bytes\"` // Raw signature bytes of the transaction.\n\tSignature      string                      `json:\"signature\"`       // Human-readable signature of the transaction's method.\n\tType           utils.TransactionMethodType `json:\"type\"`            // Type of the transaction, classified by its method name.\n\tName           string                      `json:\"name\"`            // Name of the transaction's method.\n\tMethod         *abi.Method                 `json:\"-\"`               // ABI method information, not serialized to JSON.\n\tInputs         map[string]interface{}      `json:\"inputs\"`          // Decoded arguments passed to the transaction's method.\n}\n```\nTransaction encapsulates a decoded Ethereum transaction, providing detailed information about the transaction's method, its arguments, and the associated ABI. This structured format makes it easier to work with Ethereum transactions programmatically.\n\n```go\nfunc DecodeTransactionFromAbi(data []byte, abiData []byte) (*Transaction, error)\n```\nDecodeTransactionFromAbi decodes an Ethereum transaction using the provided ABI. It extracts the method signature and arguments from the raw transaction data, constructing a Transaction object that includes this information along with the method's ABI.\n\nThe function requires the raw transaction data (\\`data\\`) and the ABI of the smart contract (\\`abiData\\`) in JSON format. It returns a pointer to a Transaction object, populated with the decoded method information and its arguments, or an error if decoding fails.\n\nThis function simplifies the process of interacting with raw Ethereum transactions, making it easier to analyze and use the transaction data programmatically.\n\n","path":"github.com/unpackdev/solgo/bytecode","name":"bytecode","synopsis":"Package bytecode provides tools for decoding and analyzing Ethereum contract, transaction, events, and log bytecode.","isRedistributable":true}
