-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package hypersyncgo | ||
|
||
import ( | ||
"context" | ||
"github.com/enviodev/hypersync-client-go/types" | ||
"github.com/ethereum/go-ethereum/common" | ||
"math/big" | ||
) | ||
|
||
// GetContractCreator fetches the transaction details of the creator of a specified contract address. | ||
// | ||
// This function sends a POST request to the Envio API to retrieve information about the contract creator. | ||
// It takes the context, network ID, and contract address as parameters and returns the transaction details. | ||
// | ||
// Parameters: | ||
// - ctx: The context for managing the request lifecycle. | ||
// - networkId: The ID of the network where the contract is deployed. | ||
// - addr: The contract address for which the creator's transaction details are to be fetched. | ||
// | ||
// Returns: | ||
// - *Transaction: The transaction details of the contract creator, if found. | ||
// - error: An error if the request fails or the contract is not found. | ||
func (c *Client) GetContractCreator(ctx context.Context, addr common.Address) (*types.QueryResponse, error) { | ||
query := types.Query{ | ||
FromBlock: big.NewInt(0), | ||
Transactions: []types.TransactionSelection{ | ||
{ | ||
ContractAddress: []common.Address{addr}, | ||
}, | ||
}, | ||
FieldSelection: types.FieldSelection{ | ||
Block: []string{"block", "hash"}, | ||
}, | ||
} | ||
return c.GetArrow(ctx, &query) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package hypersyncgo | ||
|
||
import ( | ||
"context" | ||
"github.com/enviodev/hypersync-client-go/options" | ||
"github.com/enviodev/hypersync-client-go/utils" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestGetContractCreatorByNumber(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
opts options.Options | ||
addrs []common.Address | ||
}{{ | ||
name: "Test Ethereum Client", | ||
opts: options.Options{ | ||
Blockchains: []options.Node{ | ||
{ | ||
Type: utils.EthereumNetwork, | ||
NetworkId: utils.EthereumNetworkID, | ||
Endpoint: "https://eth.hypersync.xyz", | ||
RpcEndpoint: "https://eth.rpc.hypersync.xyz", | ||
}, | ||
}, | ||
}, | ||
addrs: []common.Address{ | ||
common.HexToAddress("0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE"), | ||
}, | ||
}} | ||
|
||
for _, testCase := range testCases { | ||
t.Run(testCase.name, func(t *testing.T) { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
// Fetch the first node out of the blockchain definitions | ||
nodeOpts := testCase.opts.Blockchains[0] | ||
client, err := NewClient(ctx, nodeOpts) | ||
require.NoError(t, err) | ||
require.NotNil(t, client) | ||
|
||
for _, q := range testCase.addrs { | ||
resp, rErr := client.GetContractCreator(ctx, q) | ||
require.NoError(t, rErr) | ||
require.NotNil(t, resp) | ||
//require.Equal(t, resp., q) | ||
} | ||
|
||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters