|
| 1 | +package data_feeds |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/aptos-labs/aptos-go-sdk" |
| 5 | + "github.com/aptos-labs/aptos-go-sdk/api" |
| 6 | + "github.com/smartcontractkit/chainlink-aptos/bindings/bind" |
| 7 | + "github.com/smartcontractkit/chainlink-aptos/bindings/compile" |
| 8 | + module_registry "github.com/smartcontractkit/chainlink-aptos/bindings/data_feeds/registry" |
| 9 | + module_router "github.com/smartcontractkit/chainlink-aptos/bindings/data_feeds/router" |
| 10 | + "github.com/smartcontractkit/chainlink-aptos/contracts" |
| 11 | +) |
| 12 | + |
| 13 | +type DataFeeds interface { |
| 14 | + Address() aptos.AccountAddress |
| 15 | + |
| 16 | + Registry() module_registry.RegistryInterface |
| 17 | + Router() module_router.RouterInterface |
| 18 | +} |
| 19 | + |
| 20 | +var _ DataFeeds = DataFeedsContract{} |
| 21 | + |
| 22 | +type DataFeedsContract struct { |
| 23 | + address aptos.AccountAddress |
| 24 | + |
| 25 | + registry module_registry.RegistryInterface |
| 26 | + router module_router.RouterInterface |
| 27 | +} |
| 28 | + |
| 29 | +func (C DataFeedsContract) Address() aptos.AccountAddress { |
| 30 | + return C.address |
| 31 | +} |
| 32 | + |
| 33 | +func (C DataFeedsContract) Registry() module_registry.RegistryInterface { |
| 34 | + return C.registry |
| 35 | +} |
| 36 | +func (C DataFeedsContract) Router() module_router.RouterInterface { |
| 37 | + return C.router |
| 38 | +} |
| 39 | + |
| 40 | +var FunctionInfo = bind.MustParseFunctionInfo( |
| 41 | + module_registry.FunctionInfo, |
| 42 | + module_router.FunctionInfo, |
| 43 | +) |
| 44 | + |
| 45 | +func Compile(ownerAddress aptos.AccountAddress, platformAddress aptos.AccountAddress) (compile.CompiledPackage, error) { |
| 46 | + namedAddresses := map[string]aptos.AccountAddress{ |
| 47 | + "owner": ownerAddress, |
| 48 | + "platform": platformAddress, |
| 49 | + } |
| 50 | + // Compile using CLI |
| 51 | + return compile.CompilePackage(contracts.DataFeeds, namedAddresses) |
| 52 | +} |
| 53 | + |
| 54 | +func Bind(address aptos.AccountAddress, client aptos.AptosRpcClient) DataFeeds { |
| 55 | + return DataFeedsContract{ |
| 56 | + address: address, |
| 57 | + registry: module_registry.NewRegistry(address, client), |
| 58 | + router: module_router.NewRouter(address, client), |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// DeployToObject deploys the Data Feeds contract to a new named object. |
| 63 | +// The resulting address will be calculated using the deployer's account address and the next sequence number |
| 64 | +func DeployToObject( |
| 65 | + auth aptos.TransactionSigner, |
| 66 | + client aptos.AptosRpcClient, |
| 67 | + ownerAddress aptos.AccountAddress, |
| 68 | + platformAddress aptos.AccountAddress, |
| 69 | +) (aptos.AccountAddress, *api.PendingTransaction, DataFeeds, error) { |
| 70 | + namedAddresses := map[string]aptos.AccountAddress{ |
| 71 | + "owner": ownerAddress, |
| 72 | + "platform": platformAddress, |
| 73 | + } |
| 74 | + address, tx, err := bind.DeployPackageToObject(auth, client, contracts.DataFeeds, namedAddresses) |
| 75 | + if err != nil { |
| 76 | + return aptos.AccountAddress{}, nil, nil, err |
| 77 | + } |
| 78 | + return address, tx, Bind(address, client), nil |
| 79 | +} |
0 commit comments