Documentation
¶
Index ¶
- Constants
- Variables
- func JsonEncodeAbiTypeValue(arg abi.Type, value interface{}) (result interface{}, err error)
- func LabelHash(label string) (hash [32]byte, err error)
- func NameHash(name string) (hash [32]byte, err error)
- func Normalize(input string) (output string, err error)
- type ArgInfo
- type ChainConfig
- type Client
- func (client *Client) FetchContractReturn(web3Url *Web3URL) (contractReturn []byte, err error)
- func (client *Client) FetchUrl(url string) (fetchedUrl FetchedWeb3URL, err error)
- func (client *Client) ParseUrl(url string) (web3Url Web3URL, err error)
- func (client *Client) ProcessContractReturn(web3Url *Web3URL, contractReturn []byte) (fetchedWeb3Url FetchedWeb3URL, err error)
- func (client *Client) ProcessResourceRequestContractReturn(fetchedWeb3Url *FetchedWeb3URL, web3Url *Web3URL, contractReturn []byte) (err error)
- type Config
- type ContractCallMode
- type ContractReturnProcessing
- type DomainNameService
- type DomainNameServiceChainConfig
- type DomainNameServiceConfig
- type ErrorWithHttpCode
- type FetchedWeb3URL
- type QueryParameter
- type QueryParameters
- type ResolveMode
- type ResourceRequestReader
- type Web3URL
Constants ¶
const ( DomainNameServiceENS = "ens" DomainNameServiceW3NS = "w3ns" )
const ( ResolveModeAuto = "auto" ResolveModeManual = "manual" ResolveModeResourceRequests = "resourceRequest" )
const ( ContractCallModeCalldata = "calldata" ContractCallModeMethod = "method" )
const ( // Expect the whole returned data to be ABI-encoded bytes. Decode. ContractReturnProcessingDecodeABIEncodedBytes = "decodeABIEncodedBytes" // JSON-encode the raw bytes of the returned data ContractReturnProcessingRawBytesJsonEncoded = "jsonEncodeRawBytes" // JSON-encode the different return values ContractReturnProcessingJsonEncodeValues = "jsonEncodeValues" // Expect a string as first return value, parse it as a dataUrl // ContractReturnProcessingDataUrl = "dataUrl" // To implement // Expect a return following the erc5219 spec, will decode it using this spec ContractReturnProcessingDecodeErc5219Request = "decodeErc5219Request" )
Variables ¶
Functions ¶
func JsonEncodeAbiTypeValue ¶
Used for auto mode returning JSON : For a given ABI type and a value, convert it to a string, with the data formatted according to the spec
Types ¶
type ChainConfig ¶
type ChainConfig struct {
ChainId int
// A mapping of chain "short name" (from https://github.com/ethereum-lists/chains) to their chain id
// Used by ERC-6821 which relies on ERC-3770 addresses
ShortName string
// The RPC URL to use to call the chain
RPC string
// A chain-specific config per domain name service. Key is their short name.
DomainNameServices map[DomainNameService]DomainNameServiceChainConfig
}
type Client ¶
type Client struct {
Config *Config
DomainNameResolutionCache *localCache
}
func (*Client) FetchUrl ¶
func (client *Client) FetchUrl(url string) (fetchedUrl FetchedWeb3URL, err error)
*
- The main function of the package.
- For a given full web3:// url ("web3://xxxx"), returns a structure containing
- the bytes output and the HTTP code and headers, as well as plenty of informations on
- how the processing was done.
func (*Client) ParseUrl ¶
*
- Step 1 : Parse the URL and determine how we are going to call the main contract.
func (*Client) ProcessContractReturn ¶
func (client *Client) ProcessContractReturn(web3Url *Web3URL, contractReturn []byte) (fetchedWeb3Url FetchedWeb3URL, err error)
*
- Step 3 : Process the data returned by the main contract.
func (*Client) ProcessResourceRequestContractReturn ¶
func (client *Client) ProcessResourceRequestContractReturn(fetchedWeb3Url *FetchedWeb3URL, web3Url *Web3URL, contractReturn []byte) (err error)
Step 3 : We have the contract return, process it
type Config ¶
type Config struct {
// A config per chain. Key is the chain id
Chains map[int]ChainConfig
// A config per domain name service. Key is their short name
DomainNameServices map[DomainNameService]DomainNameServiceConfig
// There is an internal domain name resolution cache
NameAddrCacheDurationInMinutes int
}
The config used by the client to make the web3:// calls
func (*Config) GetChainIdByShortName ¶
func (*Config) GetDomainNameServiceBySuffix ¶
func (config *Config) GetDomainNameServiceBySuffix(suffix string) (result DomainNameService)
type ContractCallMode ¶
type ContractCallMode string
type ContractReturnProcessing ¶
type ContractReturnProcessing string
type DomainNameService ¶
type DomainNameService string
type DomainNameServiceChainConfig ¶
type DomainNameServiceChainConfig struct {
Id DomainNameService
// The URL to the contract of the resolver
ResolverAddress common.Address
}
Attributes of a domain name service specific to a chain
type DomainNameServiceConfig ¶
type DomainNameServiceConfig struct {
Id DomainNameService
// "eth", ...
Suffix string
// The default home chain of a domain name service; e.g. 1 for ENS, 333 for W3NS
DefaultChainId int
}
Attributes of a domain name service
type ErrorWithHttpCode ¶
An error type with a HTTP code
func (*ErrorWithHttpCode) Error ¶
func (e *ErrorWithHttpCode) Error() string
type FetchedWeb3URL ¶
type FetchedWeb3URL struct {
// The web3 URL, parsed
ParsedUrl *Web3URL
// The raw data returned by the contract
ContractReturn []byte
// The processed output, to be returned by the browser
Output io.Reader
// The HTTP code to be returned by the browser
HttpCode int
// The HTTP headers to be returned by the browser
HttpHeaders map[string]string
}
This contains the result of a web3:// URL call : the parsed URL, the raw contract return, and the bytes output, HTTP code and headers for the browser.
type QueryParameter ¶
URL.parseQuery does not preserve the order of query attributes This is a version which keep order
type QueryParameters ¶
type QueryParameters []QueryParameter
func ParseQuery ¶
func ParseQuery(query string) (params QueryParameters, err error)
type ResolveMode ¶
type ResolveMode string
type ResourceRequestReader ¶ added in v0.2.0
type ResourceRequestReader struct {
Client *Client
FetchedWeb3URL *FetchedWeb3URL
// Content of the last chunk call
Chunk []byte
Cursor int
NextChunkUrl string
}
type Web3URL ¶
type Web3URL struct {
// The actual url string "web3://...."
Url string
// If the host was a domain name, what domain name service was used?
HostDomainNameResolver DomainNameService
// Chain of the name resolution service
HostDomainNameResolverChainId int
// The contract address (after optional domain name resolution) that is going to be called,
// and its chain location
ContractAddress common.Address // actual address
ChainId int
// The ERC-4804 resolve mode
ResolveMode ResolveMode
// How do we call the smartcontract
// 'calldata' : We use a raw calldata
// 'method': We use the specified method and method parameters
ContractCallMode ContractCallMode
// Attributes for ContractCallModeCalldata
Calldata []byte
// Attributes for ContractCallModeMethod
MethodName string
MethodArgs []abi.Type
MethodArgValues []interface{}
// How to process the return of the contract. See enum for doc
ContractReturnProcessing ContractReturnProcessing
// In case of contractReturnProcessing being decodeABIEncodedBytes,
// this will set the mime type to return
DecodedABIEncodedBytesMimeType string
// In case of ContractReturnProcessing being jsonEncodeValues,
// this will tell us how to ABI-decode the returned data
JsonEncodedValueTypes []abi.Type
}
This contains a web3:// URL parsed and ready to call the main smartcontract
func (*Web3URL) ComputeCalldata ¶
If ContractCallMode is calldata, returned the stored calldata If ContractCallMode is method, compute and return it