sourcify

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2022 License: MIT Imports: 9 Imported by: 0

README

Sourcify API

Test Status made_with golang Go Reference

Golang wrapper over Sourcify API. Library implements interaction with endpoints are described in the Sourcify docs.

Install

go get github.com/dipdup-net/sourcify-api

Usage

Create API structure

api := sourcify.NewAPI("https://sourcify.dev/")

Call one of available methods

// GetFile - gets the file from the repository server
func (api *API) GetFile(ctx context.Context, chainID, address, match, filename string) (*Metadata, error)

// GetFileTreeFullMatches - Returns repository URLs for every file in the source tree for the desired chain and address. Searches only for full matches.
func (api *API) GetFileTreeFullMatches(ctx context.Context, chainID, address string) ([]string, error)

// GetFileTree - returns repository URLs for every file in the source tree for the desired chain and address. Searches for full and partial matches.
func (api *API) GetFileTree(ctx context.Context, chainID, address string) (*FileTree, error)

// GetContractAddresses - Returns all verified contracts from the repository for the desired chain. Searches for full and partial matches.
func (api *API) GetContractAddresses(ctx context.Context, chainID string) (*ContractAddresses, error)

// CheckByAddresses - Checks if contract with the desired chain and address is verified and in the repository. It will only search for perfect matches.
func (api *API) CheckByAddresses(ctx context.Context, addresses []string, chainIds []string) ([]CheckStatus, error)

// CheckAllByAddresses - Checks if contract with the desired chain and address is verified and in the repository. It will search for both perfect and partial matches.
func (api *API) CheckAllByAddresses(ctx context.Context, addresses []string, chainIds []string) ([]CheckAllStatus, error)

// GetFiles - Returns all verified sources from the repository for the desired contract address and chain, including metadata.json. Searches for full and partial matches.
func (api *API) GetFiles(ctx context.Context, chainID, address string) ([]Sources, error)

// GetFilesFullMatch - Returns all verified sources from the repository for the desired contract address and chain, including metadata.json. Searches only for full matches.
func (api *API) GetFilesFullMatch(ctx context.Context, chainID, address string) ([]File, error)

// Chains - Returns the chains (networks) added to the Sourcify. Contains both supported, unsupported, monitored, unmonitored chains.
func (api *API) Chains(ctx context.Context) ([]Chain, error)

// Health - Ping the server and see if it is alive and ready for requests.
func (api *API) Health(ctx context.Context) (string, error)

Example of using library can be found here

Verification API is not realized yet in library

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("file not found")
)

errors

Functions

This section is empty.

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API -

func NewAPI

func NewAPI(baseURL string) *API

NewAPI -

func (*API) Chains

func (api *API) Chains(ctx context.Context) ([]Chain, error)

Chains - Returns the chains (networks) added to the Sourcify. Contains both supported, unsupported, monitored, unmonitored chains.

func (*API) CheckAllByAddresses

func (api *API) CheckAllByAddresses(ctx context.Context, addresses []string, chainIds []string) ([]CheckAllStatus, error)

CheckAllByAddresses - Checks if contract with the desired chain and address is verified and in the repository. It will search for both perfect and partial matches.

func (*API) CheckByAddresses

func (api *API) CheckByAddresses(ctx context.Context, addresses []string, chainIds []string) ([]CheckStatus, error)

CheckByAddresses - Checks if contract with the desired chain and address is verified and in the repository. It will only search for perfect matches.

func (*API) GetContractAddresses

func (api *API) GetContractAddresses(ctx context.Context, chainID string) (*ContractAddresses, error)

GetContractAddresses - Returns all verified contracts from the repository for the desired chain. Searches for full and partial matches.

func (*API) GetFile

func (api *API) GetFile(ctx context.Context, chainID, address, match, filename string) (*Metadata, error)

GetFile - gets the file from the repository server

func (*API) GetFileTree

func (api *API) GetFileTree(ctx context.Context, chainID, address string) (*FileTree, error)

GetFileTree - returns repository URLs for every file in the source tree for the desired chain and address. Searches for full and partial matches.

func (*API) GetFileTreeFullMatches

func (api *API) GetFileTreeFullMatches(ctx context.Context, chainID, address string) ([]string, error)

GetFileTreeFullMatches - Returns repository URLs for every file in the source tree for the desired chain and address. Searches only for full matches.

func (*API) GetFiles

func (api *API) GetFiles(ctx context.Context, chainID, address string) (*Sources, error)

GetFiles - Returns all verified sources from the repository for the desired contract address and chain, including metadata.json. Searches for full and partial matches.

func (*API) GetFilesFullMatch

func (api *API) GetFilesFullMatch(ctx context.Context, chainID, address string) ([]File, error)

GetFilesFullMatch - Returns all verified sources from the repository for the desired contract address and chain, including metadata.json. Searches only for full matches.

func (*API) Health

func (api *API) Health(ctx context.Context) (string, error)

Health - Ping the server and see if it is alive and ready for requests.

type Chain

type Chain struct {
	Name           string         `json:"name"`
	Chain          string         `json:"chain"`
	Network        string         `json:"network"`
	Icon           string         `json:"icon"`
	RPC            []string       `json:"rpc"`
	Faucets        []string       `json:"faucets"`
	NativeCurrency NativeCurrency `json:"nativeCurrency"`
	InfoURL        string         `json:"infoURL"`
	ShortName      string         `json:"shortName"`
	ChainID        int64          `json:"chainId"`
	NetworkID      int64          `json:"networkId"`
	Slip44         int64          `json:"slip44"`
	Ens            struct {
		Registry string `json:"registry"`
	} `json:"ens"`
	Explorers            []Explorer `json:"explorers"`
	Supported            bool       `json:"supported"`
	Monitored            bool       `json:"monitored"`
	ContractFetchAddress string     `json:"contractFetchAddress"`
	TxRegex              string     `json:"txRegex"`
}

Chain -

type ChainIdStatus

type ChainIdStatus struct {
	ChainID string `json:"chainId"`
	Status  string `json:"status"`
}

ChainIdStatus -

type CheckAllStatus

type CheckAllStatus struct {
	Address  string          `json:"address"`
	ChainIds []ChainIdStatus `json:"chainIds"`
}

CheckAllStatus -

type CheckStatus

type CheckStatus struct {
	Address  string   `json:"address"`
	Status   string   `json:"status"`
	ChainIds []string `json:"chainIds"`
}

CheckStatus -

type Compiler

type Compiler struct {
	Version string `json:"version"`
}

Compiler -

type ContractAddresses

type ContractAddresses struct {
	Full    []string `json:"full"`
	Partial []string `json:"partial"`
}

ContractAddresses -

type Doc

type Doc struct {
	Kind    string                        `json:"kind"`
	Methods map[string]stdJSON.RawMessage `json:"methods"`
	Version int                           `json:"version"`
}

Doc -

type Error

type Error struct {
	Error string `json:"error"`
}

Error -

type Explorer

type Explorer struct {
	Name     string `json:"name"`
	URL      string `json:"url"`
	Standard string `json:"standard"`
}

Explorer -

type File

type File struct {
	Name    string `json:"name"`
	Path    string `json:"path"`
	Content string `json:"content"`
}

File -

type FileTree

type FileTree struct {
	Status string   `json:"status"`
	Files  []string `json:"files"`
}

FileTree -

type Metadata

type Metadata struct {
	Compiler Compiler          `json:"compiler"`
	Language string            `json:"language"`
	Output   Output            `json:"output"`
	Settings Settings          `json:"settings"`
	Sources  map[string]Source `json:"sources"`
	Version  int               `json:"version"`
}

Metadata -

func ParseMetadata

func ParseMetadata(data string) (*Metadata, error)

ParseMetadata - try to parse metadata.json

type NativeCurrency

type NativeCurrency struct {
	Name     string `json:"name"`
	Symbol   string `json:"symbol"`
	Decimals int    `json:"decimals"`
}

NativeCurrency -

type Output

type Output struct {
	ABI     stdJSON.RawMessage `json:"abi"`
	DevDoc  Doc                `json:"devdoc"`
	UserDoc Doc                `json:"userdoc"`
}

Output -

type Settings

type Settings struct {
	CompilationTarget map[string]string `json:"compilationTarget"`
	EvmVersion        string            `json:"evmVersion"`
	Libraries         struct{}          `json:"libraries"`
	Metadata          struct {
		BytecodeHash string `json:"bytecodeHash"`
	} `json:"metadata"`
	Optimizer struct {
		Enabled bool `json:"enabled"`
		Runs    int  `json:"runs"`
	} `json:"optimizer"`
	Remappings []interface{} `json:"remappings"`
}

Settings -

type Source

type Source struct {
	Keccak256 string   `json:"keccak256"`
	License   string   `json:"license"`
	Urls      []string `json:"urls"`
}

Source -

type Sources

type Sources struct {
	Status string `json:"status"`
	Files  []File `json:"files"`
}

Sources -

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL