Skip to content

Commit

Permalink
feat: offer json rpc change
Browse files Browse the repository at this point in the history
  • Loading branch information
fearlessfe authored and GrapeBaBa committed Oct 10, 2024
1 parent 28d395d commit e1bfcb4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
31 changes: 17 additions & 14 deletions p2p/discover/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,28 +415,31 @@ func (p *PortalProtocolAPI) FindContent(enr string, contentKey string) (interfac
}
}

func (p *PortalProtocolAPI) Offer(enr string, contentKey string, contentValue string) (string, error) {
func (p *PortalProtocolAPI) Offer(enr string, contentItems [][2]string) (string, error) {
n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil {
return "", err
}

contentKeyBytes, err := hexutil.Decode(contentKey)
if err != nil {
return "", err
}
contentValueBytes, err := hexutil.Decode(contentValue)
if err != nil {
return "", err
}

contentEntry := &ContentEntry{
ContentKey: contentKeyBytes,
Content: contentValueBytes,
entries := make([]*ContentEntry, 0, len(contentItems));
for _, contentItem := range contentItems {
contentKey, err := hexutil.Decode(contentItem[0])
if err != nil {
return "", err
}
contentValue, err := hexutil.Decode(contentItem[1])
if err != nil {
return "", err
}
contentEntry := &ContentEntry{
ContentKey: contentKey,
Content: contentValue,
}
entries = append(entries, contentEntry)
}

transientOfferRequest := &TransientOfferRequest{
Contents: []*ContentEntry{contentEntry},
Contents: entries,
}

offerReq := &OfferRequest{
Expand Down
4 changes: 2 additions & 2 deletions portalnetwork/beacon/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (p *API) BeaconFindContent(enr string, contentKey string) (interface{}, err
return p.FindContent(enr, contentKey)
}

func (p *API) BeaconOffer(enr string, contentKey string, contentValue string) (string, error) {
return p.Offer(enr, contentKey, contentValue)
func (p *API) BeaconOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentItems)
}

func (p *API) BeaconRecursiveFindNodes(nodeId string) ([]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions portalnetwork/history/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (p *API) HistoryFindContent(enr string, contentKey string) (interface{}, er
return p.FindContent(enr, contentKey)
}

func (p *API) HistoryOffer(enr string, contentKey string, contentValue string) (string, error) {
return p.Offer(enr, contentKey, contentValue)
func (p *API) HistoryOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentItems)
}

func (p *API) HistoryRecursiveFindNodes(nodeId string) ([]string, error) {
Expand Down
4 changes: 2 additions & 2 deletions portalnetwork/state/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (p *API) StateFindContent(enr string, contentKey string) (interface{}, erro
return p.FindContent(enr, contentKey)
}

func (p *API) StateOffer(enr string, contentKey string, contentValue string) (string, error) {
return p.Offer(enr, contentKey, contentValue)
func (p *API) StateOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentItems)
}

func (p *API) StateRecursiveFindNodes(nodeId string) ([]string, error) {
Expand Down

0 comments on commit e1bfcb4

Please sign in to comment.