Skip to content

Commit c0aebc4

Browse files
committed
Fixing up the examples package
1 parent 5408482 commit c0aebc4

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

examples/chains.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/txpull/sourcify-go"
99
)
1010

11+
// Example_GetChains demonstrates how to retrieve chains using the Sourcify client.
1112
func Example_GetChains() {
1213
// Create a custom HTTP client with timeout
1314
httpClient := &http.Client{
@@ -24,13 +25,12 @@ func Example_GetChains() {
2425
),
2526
)
2627

27-
// Call the API method
28+
// Call get chains to retrieve all chains from Sourcify
2829
chains, err := sourcify.GetChains(client)
2930
if err != nil {
3031
panic(err)
3132
}
3233

33-
// Process the response
3434
for _, chain := range chains {
3535
fmt.Printf("Chain: %+v\n\n", chain)
3636
}

examples/check_addresses.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/txpull/sourcify-go"
99
)
1010

11+
// Example_CheckAddresses demonstrates how to check contract addresses using the Sourcify client.
1112
func Example_CheckAddresses() {
1213
// Create a custom HTTP client with timeout
1314
httpClient := &http.Client{
@@ -24,21 +25,25 @@ func Example_CheckAddresses() {
2425
),
2526
)
2627

28+
// Define contract addresses to check
2729
contractAddresses := []string{
2830
"0x054B2223509D430269a31De4AE2f335890be5C8F",
2931
}
3032

33+
// Define chain IDs to check
3134
chainIds := []int{
3235
56, // Binance Smart Chain
3336
1, // Ethereum Mainnet
3437
137, // Polygon
3538
}
3639

40+
// Call the API method to check contract addresses
3741
checks, err := sourcify.CheckContractByAddresses(client, contractAddresses, chainIds, sourcify.MethodMatchTypeAny)
3842
if err != nil {
3943
panic(err)
4044
}
4145

46+
// Process the response
4247
for _, check := range checks {
4348
fmt.Printf("Contract Addresses Check Response: %+v\n", check)
4449
}

examples/examples.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Package examples provides example code snippets demonstrating the usage of the Sourcify Go client.
2+
//
3+
// These examples showcase various API methods and illustrate how to interact with the Sourcify server
4+
// to retrieve contract information, source code, metadata, file trees, and more.
5+
//
6+
// The examples demonstrate the configuration of a custom HTTP client, setting base URLs, retry options,
7+
// and making API calls to retrieve data from the Sourcify server.
8+
//
9+
// Each example function provides a self-contained code snippet that can be executed independently.
10+
// Simply copy the desired example function and execute it in your Go environment to see the output.
11+
package examples

examples/get_all_addresses.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/txpull/sourcify-go"
99
)
1010

11+
// Example_GetAllAddresses demonstrates how to retrieve all available contract addresses using the Sourcify client.
1112
func Example_GetAllAddresses() {
1213
// Create a custom HTTP client with timeout
1314
httpClient := &http.Client{
@@ -24,12 +25,15 @@ func Example_GetAllAddresses() {
2425
),
2526
)
2627

27-
// Call the API method
28+
// Call the API method to retrieve all available contract addresses
2829
addresses, err := sourcify.GetAvailableContractAddresses(client, 56)
2930
if err != nil {
3031
panic(err)
3132
}
3233

34+
// Print the number of full match addresses
3335
fmt.Printf("Full Match Addresses: %d\n", len(addresses.Full))
36+
37+
// Print the number of partial match addresses
3438
fmt.Printf("Partial Match Addresses: %d\n\n", len(addresses.Partial))
3539
}

examples/get_files.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/txpull/sourcify-go"
1010
)
1111

12+
// Example_GetFiles demonstrates how to retrieve source files for a contract using the Sourcify client.
1213
func Example_GetFiles() {
1314
// Create a custom HTTP client with timeout
1415
httpClient := &http.Client{
@@ -25,14 +26,16 @@ func Example_GetFiles() {
2526
),
2627
)
2728

28-
// Get files for the Binance Smart Chain with the address of the R3T contract
29+
// Get source files for the Binance Smart Chain with the address of the R3T contract
2930
files, err := sourcify.GetContractFiles(client, 56, common.HexToAddress("0x054B2223509D430269a31De4AE2f335890be5C8F"), sourcify.MethodMatchTypeAny)
3031
if err != nil {
3132
panic(err)
3233
}
3334

35+
// Print the status of the response
3436
fmt.Printf("Status: %+v\n", files.Status)
3537

38+
// Print the paths of the retrieved files
3639
for _, file := range files.Files {
3740
fmt.Printf("Path: %+v\n", file)
3841
}

examples/get_metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/txpull/sourcify-go"
1010
)
1111

12+
// Example_GetMetadata demonstrates how to retrieve full metadata for a contract using the Sourcify client.
1213
func Example_GetMetadata() {
1314
// Create a custom HTTP client with timeout
1415
httpClient := &http.Client{
@@ -31,5 +32,6 @@ func Example_GetMetadata() {
3132
panic(err)
3233
}
3334

35+
// Print the full match metadata
3436
fmt.Printf("Full Match Metadata: %+v\n", fullMetadata)
3537
}

examples/get_source_code.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/txpull/sourcify-go"
1010
)
1111

12+
// Example_GetSourceCode demonstrates how to retrieve source code for a contract using the Sourcify client.
1213
func Example_GetSourceCode() {
1314
// Create a custom HTTP client with timeout
1415
httpClient := &http.Client{
@@ -25,14 +26,16 @@ func Example_GetSourceCode() {
2526
),
2627
)
2728

28-
// Get full metadata for the Binance Smart Chain with the address of the R3T contract
29+
// Get source code for the Binance Smart Chain with the address of the R3T contract
2930
sources, err := sourcify.GetContractSourceCode(client, 56, common.HexToAddress("0x054B2223509D430269a31De4AE2f335890be5C8F"), sourcify.MethodMatchTypeAny)
3031
if err != nil {
3132
panic(err)
3233
}
3334

35+
// Print the status of the source code retrieval
3436
fmt.Printf("Status: %+v\n", sources.Status)
3537

38+
// Iterate over the source code files and print their names and paths
3639
for _, source := range sources.Code {
3740
fmt.Printf("Name: %+v\n", source.Name)
3841
fmt.Printf("Path: %+v\n", source.Path)

examples/health.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/txpull/sourcify-go"
99
)
1010

11+
// Example_GetHealth demonstrates how to check the health status of the Sourcify server using the Sourcify client.
1112
func Example_GetHealth() {
1213
// Create a custom HTTP client with timeout
1314
httpClient := &http.Client{
@@ -24,12 +25,12 @@ func Example_GetHealth() {
2425
),
2526
)
2627

27-
// Call the API method
28+
// Call the API method to get the health status
2829
status, err := sourcify.GetHealth(client)
2930
if err != nil {
3031
panic(err)
3132
}
3233

33-
// Process the response
34+
// Print the server's health status
3435
fmt.Printf("Is server alive and ready to receive requests: %v\n", status)
3536
}

0 commit comments

Comments
 (0)