feat: offer json rpc change

This commit is contained in:
fearlessfe 2024-10-09 23:45:14 +08:00 committed by Chen Kai
parent 28d395dccc
commit e1bfcb45d9
4 changed files with 23 additions and 20 deletions

View file

@ -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) n, err := enode.Parse(enode.ValidSchemes, enr)
if err != nil { if err != nil {
return "", err return "", err
} }
contentKeyBytes, err := hexutil.Decode(contentKey) entries := make([]*ContentEntry, 0, len(contentItems));
if err != nil { for _, contentItem := range contentItems {
return "", err contentKey, err := hexutil.Decode(contentItem[0])
} if err != nil {
contentValueBytes, err := hexutil.Decode(contentValue) return "", err
if err != nil { }
return "", err contentValue, err := hexutil.Decode(contentItem[1])
} if err != nil {
return "", err
contentEntry := &ContentEntry{ }
ContentKey: contentKeyBytes, contentEntry := &ContentEntry{
Content: contentValueBytes, ContentKey: contentKey,
Content: contentValue,
}
entries = append(entries, contentEntry)
} }
transientOfferRequest := &TransientOfferRequest{ transientOfferRequest := &TransientOfferRequest{
Contents: []*ContentEntry{contentEntry}, Contents: entries,
} }
offerReq := &OfferRequest{ offerReq := &OfferRequest{

View file

@ -40,8 +40,8 @@ func (p *API) BeaconFindContent(enr string, contentKey string) (interface{}, err
return p.FindContent(enr, contentKey) return p.FindContent(enr, contentKey)
} }
func (p *API) BeaconOffer(enr string, contentKey string, contentValue string) (string, error) { func (p *API) BeaconOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentKey, contentValue) return p.Offer(enr, contentItems)
} }
func (p *API) BeaconRecursiveFindNodes(nodeId string) ([]string, error) { func (p *API) BeaconRecursiveFindNodes(nodeId string) ([]string, error) {

View file

@ -40,8 +40,8 @@ func (p *API) HistoryFindContent(enr string, contentKey string) (interface{}, er
return p.FindContent(enr, contentKey) return p.FindContent(enr, contentKey)
} }
func (p *API) HistoryOffer(enr string, contentKey string, contentValue string) (string, error) { func (p *API) HistoryOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentKey, contentValue) return p.Offer(enr, contentItems)
} }
func (p *API) HistoryRecursiveFindNodes(nodeId string) ([]string, error) { func (p *API) HistoryRecursiveFindNodes(nodeId string) ([]string, error) {

View file

@ -40,8 +40,8 @@ func (p *API) StateFindContent(enr string, contentKey string) (interface{}, erro
return p.FindContent(enr, contentKey) return p.FindContent(enr, contentKey)
} }
func (p *API) StateOffer(enr string, contentKey string, contentValue string) (string, error) { func (p *API) StateOffer(enr string, contentItems [][2]string) (string, error) {
return p.Offer(enr, contentKey, contentValue) return p.Offer(enr, contentItems)
} }
func (p *API) StateRecursiveFindNodes(nodeId string) ([]string, error) { func (p *API) StateRecursiveFindNodes(nodeId string) ([]string, error) {