diff --git a/thirdweb/ipfs_storage.go b/thirdweb/ipfs_storage.go index f16f785..624e070 100644 --- a/thirdweb/ipfs_storage.go +++ b/thirdweb/ipfs_storage.go @@ -34,12 +34,14 @@ type uploadResponse struct { } type IpfsStorage struct { - GatewayUrl string + gatewayUrl string + httpClient *http.Client } -func newIpfsStorage(gatewayUrl string) *IpfsStorage { +func newIpfsStorage(gatewayUrl string, httpClient *http.Client) *IpfsStorage { return &IpfsStorage{ - GatewayUrl: gatewayUrl, + gatewayUrl: gatewayUrl, + httpClient: httpClient, } } @@ -51,8 +53,8 @@ func newIpfsStorage(gatewayUrl string) *IpfsStorage { // // returns: byte data of the IPFS data at the URI func (ipfs *IpfsStorage) Get(uri string) ([]byte, error) { - gatewayUrl := replaceHashWithGatewayUrl(uri, ipfs.GatewayUrl) - resp, err := http.Get(gatewayUrl) + gatewayUrl := replaceHashWithGatewayUrl(uri, ipfs.gatewayUrl) + resp, err := ipfs.httpClient.Get(gatewayUrl) if err != nil { return nil, err } @@ -258,7 +260,7 @@ func (ipfs *IpfsStorage) uploadBatchWithCid( // returns - map[string]interface{} func (ipfs *IpfsStorage) batchUploadProperties(data []map[string]interface{}) (interface{}, error) { - sanitizedMetadatas, err := ipfs.replaceGatewayUrlWithHash(data, "ipfs://", ipfs.GatewayUrl) + sanitizedMetadatas, err := ipfs.replaceGatewayUrlWithHash(data, "ipfs://", ipfs.gatewayUrl) if err != nil { return nil, err } diff --git a/thirdweb/sdk.go b/thirdweb/sdk.go index 1632bfb..b5444e5 100644 --- a/thirdweb/sdk.go +++ b/thirdweb/sdk.go @@ -2,6 +2,7 @@ package thirdweb import ( "fmt" + "net/http" "strings" "github.com/ethereum/go-ethereum/common" @@ -40,6 +41,7 @@ func NewThirdwebSDKFromProvider(provider *ethclient.Client, options *SDKOptions) // Define defaults for all the options privateKey := "" gatewayUrl := defaultIpfsGatewayUrl + httpClient := http.DefaultClient // Override defaults with the options that are defined if options != nil { @@ -50,9 +52,13 @@ func NewThirdwebSDKFromProvider(provider *ethclient.Client, options *SDKOptions) if options.GatewayUrl != "" { gatewayUrl = options.GatewayUrl } + + if options.HttpClient != nil { + httpClient = options.HttpClient + } } - storage := newIpfsStorage(gatewayUrl) + storage := newIpfsStorage(gatewayUrl, httpClient) handler, err := NewProviderHandler(provider, privateKey) if err != nil { @@ -230,13 +236,13 @@ func getDefaultRpcUrl(rpcUrlorName string) (string, error) { case "avalanche": return defaultRpc("avalanche") case "optimism": - return defaultRpc("optimism"); + return defaultRpc("optimism") case "optimism-goerli": - return defaultRpc("optimism-goerli"); + return defaultRpc("optimism-goerli") case "arbitrum": - return defaultRpc("arbitrum"); + return defaultRpc("arbitrum") case "arbitrum-goerli": - return defaultRpc("arbitrum-goerli"); + return defaultRpc("arbitrum-goerli") default: if strings.HasPrefix(rpcUrlorName, "http") { return rpcUrlorName, nil diff --git a/thirdweb/sharded_merkle_tree_test.go b/thirdweb/sharded_merkle_tree_test.go index 4e96ccd..11942a5 100644 --- a/thirdweb/sharded_merkle_tree_test.go +++ b/thirdweb/sharded_merkle_tree_test.go @@ -6,6 +6,7 @@ import ( "encoding/hex" "encoding/json" "fmt" + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -18,7 +19,7 @@ func TestMerkleTreeSmall(t *testing.T) { } uri := "ipfs://QmeAx8aRvsYXN6mzky72b9V1HWokb271FoBmDu4tatC8hE/0" - storage := newIpfsStorage(defaultIpfsGatewayUrl) + storage := newIpfsStorage(defaultIpfsGatewayUrl, http.DefaultClient) body, err := storage.Get(uri) if err != nil { @@ -48,7 +49,7 @@ func TestMerkleTreeEdgeCase(t *testing.T) { } uri := "ipfs://QmacDnA4i7Za19LpE3pngwLfUtakn71ghaKKjTkM2Phzj8/0" - storage := newIpfsStorage(defaultIpfsGatewayUrl) + storage := newIpfsStorage(defaultIpfsGatewayUrl, http.DefaultClient) body, err := storage.Get(uri) if err != nil { @@ -83,4 +84,4 @@ func TestMerkleTreeEdgeCase(t *testing.T) { assert.Equal(t, bytes.Compare(proof.Proof[i][:], proofBytes), 0) } -} \ No newline at end of file +} diff --git a/thirdweb/types.go b/thirdweb/types.go index 3c5a89c..80d040a 100644 --- a/thirdweb/types.go +++ b/thirdweb/types.go @@ -2,6 +2,7 @@ package thirdweb import ( "math/big" + "net/http" "time" "github.com/ethereum/go-ethereum/common" @@ -11,6 +12,7 @@ import ( type SDKOptions struct { PrivateKey string GatewayUrl string + HttpClient *http.Client } type Metadata struct { @@ -65,26 +67,26 @@ type EditionMetadataInput struct { } type ClaimVerification struct { - Value *big.Int - Proofs [][32]byte - MaxClaimable *big.Int - Price *big.Int - CurrencyAddress string - PriceInProof *big.Int - CurrencyAddressInProof string + Value *big.Int + Proofs [][32]byte + MaxClaimable *big.Int + Price *big.Int + CurrencyAddress string + PriceInProof *big.Int + CurrencyAddressInProof string } type ClaimConditionOutput struct { - StartTime time.Time - MaxClaimableSupply *big.Int - MaxClaimablePerWallet *big.Int - CurrentMintSupply *big.Int - AvailableSupply *big.Int - WaitInSeconds *big.Int - Price *big.Int - CurrencyAddress string - CurrencyMetadata *CurrencyValue - MerkleRootHash [32]byte + StartTime time.Time + MaxClaimableSupply *big.Int + MaxClaimablePerWallet *big.Int + CurrentMintSupply *big.Int + AvailableSupply *big.Int + WaitInSeconds *big.Int + Price *big.Int + CurrencyAddress string + CurrencyMetadata *CurrencyValue + MerkleRootHash [32]byte } type Currency struct { Name string @@ -528,7 +530,7 @@ type ClaimArguments struct { Currency common.Address PricePerToken *big.Int AllowlistProof abi.IDropAllowlistProof - Data []byte + Data []byte } type ClaimInfo struct { @@ -557,7 +559,7 @@ func (condition *ClaimConditionInput) fillDefaults() { type SnapshotEntryWithProof struct { Address string MaxClaimable string - Price string + Price string CurrencyAddress string Proof [][32]byte } @@ -569,20 +571,20 @@ func (entry *SnapshotEntryWithProof) fillDefaults() { } type ShardedMerkleTreeInfo struct { - MerkleRoot string `json:"merkleRoot"` - BaseUri string `json:"baseUri"` - OriginalEntriesUri string `json:"originalEntriesUri"` - ShardNybbles int `json:"shardNybbles"` - TokenDecimals int `json:"tokenDecimals"` + MerkleRoot string `json:"merkleRoot"` + BaseUri string `json:"baseUri"` + OriginalEntriesUri string `json:"originalEntriesUri"` + ShardNybbles int `json:"shardNybbles"` + TokenDecimals int `json:"tokenDecimals"` } type SnapshotEntry struct { - Address string `json:"address"` - MaxClaimable string `json:"maxClaimable"` - Price string `json:"price"` - CurrencyAddress string `json:"currencyAddress"` + Address string `json:"address"` + MaxClaimable string `json:"maxClaimable"` + Price string `json:"price"` + CurrencyAddress string `json:"currencyAddress"` } type ShardData struct { - Proofs []string `json:"proofs"` + Proofs []string `json:"proofs"` Entries []SnapshotEntry `json:"entries"` }