From fab589c5b9e755cd534a7f3f56b2819254af50ac Mon Sep 17 00:00:00 2001 From: Chris Marslender Date: Fri, 2 Aug 2024 13:06:05 -0500 Subject: [PATCH] Add get_mirrors endpoint --- pkg/rpc/datalayer.go | 31 ++++++++++++++++++++++++++++++- pkg/types/datalayer.go | 15 +++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 pkg/types/datalayer.go diff --git a/pkg/rpc/datalayer.go b/pkg/rpc/datalayer.go index 53a99fe..3a00d6d 100644 --- a/pkg/rpc/datalayer.go +++ b/pkg/rpc/datalayer.go @@ -4,6 +4,7 @@ import ( "net/http" "github.com/chia-network/go-chia-libs/pkg/rpcinterface" + "github.com/chia-network/go-chia-libs/pkg/types" ) // DataLayerService encapsulates data layer RPC methods @@ -70,7 +71,7 @@ func (s *DataLayerService) Subscriptions(opts *DatalayerGetSubscriptionsOptions) } // DatalayerGetOwnedStoresOptions Options for get_owned_stores -type DatalayerGetOwnedStoresOptions struct {} +type DatalayerGetOwnedStoresOptions struct{} // DatalayerGetOwnedStoresResponse Response for get_owned_stores type DatalayerGetOwnedStoresResponse struct { @@ -94,3 +95,31 @@ func (s *DataLayerService) GetOwnedStores(opts *DatalayerGetOwnedStoresOptions) return r, resp, nil } + +// DatalayerGetMirrorsOptions Options for get_mirrors +type DatalayerGetMirrorsOptions struct { + ID string `json:"id"` // Hex String +} + +// DatalayerGetMirrorsResponse Response from the get_mirrors RPC +type DatalayerGetMirrorsResponse struct { + Response + Mirrors []types.DatalayerMirror `json:"mirrors"` +} + +// GetMirrors lists the mirrors for the given datalayer store +func (s *DataLayerService) GetMirrors(opts *DatalayerGetMirrorsOptions) (*DatalayerGetMirrorsResponse, *http.Response, error) { + request, err := s.NewRequest("get_mirrors", opts) + if err != nil { + return nil, nil, err + } + + r := &DatalayerGetMirrorsResponse{} + + resp, err := s.Do(request, r) + if err != nil { + return nil, resp, err + } + + return r, resp, nil +} diff --git a/pkg/types/datalayer.go b/pkg/types/datalayer.go new file mode 100644 index 0000000..8d437f3 --- /dev/null +++ b/pkg/types/datalayer.go @@ -0,0 +1,15 @@ +package types + +import ( + "github.com/samber/mo" +) + +// DatalayerMirror represents a single mirror for a data store +type DatalayerMirror struct { + CoinID Bytes32 `json:"coin_id"` + LauncherID Bytes32 `json:"launcher_id"` + Amount uint64 `json:"amount"` + URLs []string `json:"urls"` + Ours bool `json:"ours"` + ConfirmedAtHeight mo.Option[uint32] `json:"confirmed_at_height"` +}