Skip to content

Commit

Permalink
Add get_mirrors endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
cmmarslender committed Aug 2, 2024
1 parent 29c94e4 commit fab589c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/rpc/datalayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
15 changes: 15 additions & 0 deletions pkg/types/datalayer.go
Original file line number Diff line number Diff line change
@@ -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"`
}

0 comments on commit fab589c

Please sign in to comment.