Documentation
¶
Overview ¶
Package metadata provides functionality for interacting with IPFS/SWARM and retrieving contract metadata.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidIpfsClient = errors.New("invalid ipfs client provided") ErrIpfsClientNotAvailable = errors.New("ipfs client seems not to be available. please check your ipfs daemon") )
Functions ¶
This section is empty.
Types ¶
type ContractMetadata ¶
type ContractMetadata struct { Raw string `json:"raw"` Version int `json:"version"` Compiler struct { Version string `json:"version"` Keccak256 string `json:"keccak256"` } `json:"compiler"` Language string `json:"language"` Settings struct { EvmVersion string `json:"evmVersion"` CompilationTarget map[string]string `json:"compilationTarget"` Libraries interface{} `json:"libraries"` Remappings []string `json:"remappings"` Metadata struct { BytecodeHash string `json:"bytecodeHash"` UseLiteralContent bool `json:"useLiteralContent"` AppendCBOR bool `json:"appendCBOR"` } `json:"metadata"` Optimizer struct { Enabled bool `json:"enabled"` Runs int `json:"runs"` Details struct { Peephole bool `json:"peephole"` Inliner bool `json:"inliner"` JumpdestRemover bool `json:"jumpdestRemover"` OrderLiterals bool `json:"orderLiterals"` Deduplicate bool `json:"deduplicate"` Cse bool `json:"cse"` ConstantOptimizer bool `json:"constantOptimizer"` Yul bool `json:"yul"` YulDetails struct { StackAllocation bool `json:"stackAllocation"` OptimizerSteps interface{} `json:"optimizerSteps"` } `json:"yulDetails"` } `json:"details"` } `json:"optimizer"` } `json:"settings"` Output struct { Abi []interface{} `json:"abi"` } Sources map[string]ContractSource `json:"sources"` }
ContractMetadata represents the metadata of a contract stored in IPFS. The metadata includes information about the compiler, language, settings, output, and sources. The Raw field contains the raw metadata as a string. See https://docs.soliditylang.org/en/v0.8.19/metadata.html @TODO: Devdoc and userdoc are not included in the struct as I see very small amount of reasons to use them in this moment. If you need them, please consider doing a PR to add them. :) Basically lots of the times devdoc and userdoc lack information so they are not very useful. You can use .Raw to extract dev and user doc if you need them.
func (*ContractMetadata) AbiToJSON ¶
func (c *ContractMetadata) AbiToJSON() (string, error)
AbiToJSON converts the ABI of the contract to a JSON string. It returns the JSON string or an error if the conversion fails.
func (*ContractMetadata) ToJSON ¶
func (c *ContractMetadata) ToJSON() ([]byte, error)
ToJSON converts the ContractMetadata object to a JSON byte array. It returns the byte array or an error if the conversion fails.
func (*ContractMetadata) ToProto ¶
func (c *ContractMetadata) ToProto() *metadata_pb.Metadata
type ContractSource ¶ added in v0.3.1
type IpfsProvider ¶
type IpfsProvider struct {
// contains filtered or unexported fields
}
IpfsProvider is a struct that holds the context and the client for IPFS operations.
func (*IpfsProvider) GetMetadataByCID ¶
func (p *IpfsProvider) GetMetadataByCID(cid string) (*ContractMetadata, error)
GetMetadataByCID retrieves the metadata of a contract by its CID (Content Identifier). It first extracts the hash from the CID, then uses the IPFS client to retrieve the content associated with the hash. It reads the content, unmarshals it into a ContractMetadata object, and returns it. If any of these operations fail, it returns an error.
type Provider ¶
type Provider interface { // GetMetadataByCID returns the metadata of a contract by the CID (Content Identifier) of the contract GetMetadataByCID(cid string) (*ContractMetadata, error) }
Provider is the interface that wraps the basic interaction with contract metadata from different sources such as IPFS, SWARM, etc....
func NewIpfsProvider ¶
NewIpfsProvider creates a new instance of IpfsProvider. It takes a context and an IPFS client as parameters. If the client is nil, it returns an error. Otherwise, it returns a new instance of IpfsProvider.