Skip to content

Commit f61cef1

Browse files
authored
Merge pull request #613 from oasisprotocol/matevz/feature/rofl-show-offers-note
cmd/rofl/deploy: Also show a "note" metadata when listing offers
2 parents 5d97b2e + 6b13fda commit f61cef1

3 files changed

Lines changed: 65 additions & 11 deletions

File tree

build/rofl/provider/manifest.go

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func (m *Manifest) Save() error {
173173
type Offer struct {
174174
// ID is the unique offer identifier used by the scheduler.
175175
ID string `yaml:"id" json:"id"`
176+
// Note contains one-line notification such as a discount or a warning.
177+
Note string `yaml:"note" json:"note"`
178+
// Description contains longer offer-specific description such as intended applications.
179+
Description string `yaml:"description" json:"description"`
176180
// Resources are the offered resources.
177181
Resources Resources `yaml:"resources" json:"resources"`
178182
// Payment is the payment for this offer.
@@ -205,6 +209,12 @@ const schedulerMetadataPrefix = "net.oasis.scheduler."
205209
// SchedulerMetadataOfferKey is the metadata key used for the offer name.
206210
const SchedulerMetadataOfferKey = schedulerMetadataPrefix + "offer"
207211

212+
// NoteMetadataKey is the metadata key for offer-specific one-line notification such as a discount or a warning.
213+
const NoteMetadataKey = "net.oasis.note"
214+
215+
// DescriptionMetadataKey is the metadata key for longer offer-specific description such as intended applications.
216+
const DescriptionMetadataKey = "net.oasis.description"
217+
208218
// GetMetadata derives metadata from the attributes defined in the offer and combines it with the
209219
// specified metadata.
210220
func (o *Offer) GetMetadata() map[string]string {
@@ -221,6 +231,13 @@ func (o *Offer) GetMetadata() map[string]string {
221231
meta[schedulerMetadataPrefix+md.name] = md.value
222232
}
223233

234+
if o.Description != "" {
235+
meta[DescriptionMetadataKey] = o.Description
236+
}
237+
if o.Note != "" {
238+
meta[NoteMetadataKey] = o.Note
239+
}
240+
224241
maps.Copy(meta, o.Metadata)
225242
return meta
226243
}
@@ -250,15 +267,11 @@ const (
250267

251268
// Payment is payment configuration for an offer.
252269
type Payment struct {
253-
Native *struct {
254-
Denomination string `yaml:"denomination" json:"denomination"`
255-
Terms map[string]string `yaml:"terms" json:"terms"`
256-
} `yaml:"native,omitempty" json:"native,omitempty"`
257-
258-
EvmContract *struct {
259-
Address string `json:"address"`
260-
Data string `json:"data"`
261-
} `yaml:"evm,omitempty" json:"evm,omitempty"`
270+
// Native contains native payment terms.
271+
Native *NativePayment `yaml:"native,omitempty" json:"native,omitempty"`
272+
273+
// EvmContract contains payment terms defined in a smart contract.
274+
EvmContract *EVMContractPayment `yaml:"evm,omitempty" json:"evm,omitempty"`
262275
}
263276

264277
// Validate validates the payment configuration.
@@ -336,6 +349,24 @@ func (p *Payment) AsDescriptor(pt *config.ParaTime) (*roflmarket.Payment, error)
336349
return &dsc, nil
337350
}
338351

352+
// NativePayment is payment configuration for native tokens.
353+
type NativePayment struct {
354+
// Denomination is the native token denomination.
355+
Denomination string `yaml:"denomination,omitempty" json:"denomination,omitempty"`
356+
357+
// Terms are payment terms in form of Term => amount in decimal.
358+
Terms map[string]string `yaml:"terms" json:"terms"`
359+
}
360+
361+
// EVMContractPayment is payment configuration for EVM contract-based payments.
362+
type EVMContractPayment struct {
363+
// Address is hex-encoded address without leading 0x.
364+
Address string `json:"address"`
365+
366+
// Data is arbitrary Base-64 encoded payment information.
367+
Data string `json:"data"`
368+
}
369+
339370
// Resources are describe the offered resources.
340371
type Resources struct {
341372
// TEE is the type of TEE hardware.

cmd/rofl/deploy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ func showProviderOffer(ctx context.Context, offer *roflmarket.Offer) {
415415
offer.Resources.CPUCount,
416416
float64(offer.Resources.Storage)/1024.,
417417
)
418+
if _, ok := offer.Metadata[provider.NoteMetadataKey]; ok {
419+
fmt.Printf(" Note: %s\n", offer.Metadata[provider.NoteMetadataKey])
420+
}
421+
if _, ok := offer.Metadata[provider.DescriptionMetadataKey]; ok {
422+
fmt.Printf(" Description:\n %s\n", strings.ReplaceAll(offer.Metadata[provider.DescriptionMetadataKey], "\n", "\n "))
423+
}
418424
if offer.Payment.Native != nil {
419425
if len(offer.Payment.Native.Terms) == 0 {
420426
return

cmd/rofl/provider/mgmt.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,31 @@ var (
4343
}
4444

4545
fmt.Printf("Scheduler app: %s\n", schedulerApp)
46-
47-
// Create a default manifest.
4846
manifest := provider.Manifest{
4947
Network: npa.NetworkName,
5048
ParaTime: npa.ParaTimeName,
5149
Provider: npa.AccountName,
5250
SchedulerApp: schedulerApp,
5351
PaymentAddress: npa.AccountName,
52+
Offers: []*provider.Offer{{
53+
ID: "example_offer",
54+
Note: "One-liner note for special discounts or warnings (optional)",
55+
Description: "This is an example offer.\nFill in your description here.",
56+
Resources: provider.Resources{
57+
TEE: "tdx",
58+
Memory: 1024,
59+
CPUCount: 1,
60+
Storage: 3000,
61+
},
62+
Payment: provider.Payment{
63+
Native: &provider.NativePayment{
64+
Terms: map[string]string{
65+
provider.TermKeyMonth: "100",
66+
},
67+
},
68+
},
69+
Capacity: 10,
70+
}},
5471
}
5572
err := manifest.Validate()
5673
cobra.CheckErr(err)

0 commit comments

Comments
 (0)