-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_files.go
41 lines (35 loc) · 1.1 KB
/
get_files.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package examples
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/unpackdev/sourcify-go"
"net/http"
"time"
)
// Example_GetFiles demonstrates how to retrieve source files for a contract using the Sourcify client.
func Example_GetFiles() {
// Create a custom HTTP client with timeout
httpClient := &http.Client{
Timeout: 30 * time.Second,
}
// Create a new Sourcify client with custom options
client := sourcify.NewClient(
sourcify.WithHTTPClient(httpClient),
sourcify.WithBaseURL("https://sourcify.dev/server"),
sourcify.WithRetryOptions(
sourcify.WithMaxRetries(3),
sourcify.WithDelay(2*time.Second),
),
)
// Get source files for the Binance Smart Chain with the address of the R3T contract
files, err := sourcify.GetContractFiles(client, 56, common.HexToAddress("0x054B2223509D430269a31De4AE2f335890be5C8F"), sourcify.MethodMatchTypeAny)
if err != nil {
panic(err)
}
// Print the status of the response
fmt.Printf("Status: %+v\n", files.Status)
// Print the paths of the retrieved files
for _, file := range files.Files {
fmt.Printf("Path: %+v\n", file)
}
}