Skip to content

Commit c0ed63e

Browse files
Add IsClientRequest function for actions.
1 parent d3d9a07 commit c0ed63e

File tree

3 files changed

+135
-1
lines changed

3 files changed

+135
-1
lines changed

dist/golang/actions/actions.go

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ type Action interface {
1515
Code() string
1616
TypeName() string
1717

18+
IsClientRequest() bool
19+
1820
Validate() error
1921
Equal(proto.Message) bool
2022
}
@@ -269,6 +271,10 @@ func (a *ContractOffer) TypeName() string {
269271
return "ContractOffer"
270272
}
271273

274+
func (a *ContractOffer) IsClientRequest() bool {
275+
return true
276+
}
277+
272278
func (a *ContractFormation) Code() string {
273279
return CodeContractFormation
274280
}
@@ -277,6 +283,10 @@ func (a *ContractFormation) TypeName() string {
277283
return "ContractFormation"
278284
}
279285

286+
func (a *ContractFormation) IsClientRequest() bool {
287+
return false
288+
}
289+
280290
func (a *ContractAmendment) Code() string {
281291
return CodeContractAmendment
282292
}
@@ -285,6 +295,10 @@ func (a *ContractAmendment) TypeName() string {
285295
return "ContractAmendment"
286296
}
287297

298+
func (a *ContractAmendment) IsClientRequest() bool {
299+
return true
300+
}
301+
288302
func (a *StaticContractFormation) Code() string {
289303
return CodeStaticContractFormation
290304
}
@@ -293,6 +307,10 @@ func (a *StaticContractFormation) TypeName() string {
293307
return "StaticContractFormation"
294308
}
295309

310+
func (a *StaticContractFormation) IsClientRequest() bool {
311+
return false
312+
}
313+
296314
func (a *ContractAddressChange) Code() string {
297315
return CodeContractAddressChange
298316
}
@@ -301,6 +319,10 @@ func (a *ContractAddressChange) TypeName() string {
301319
return "ContractAddressChange"
302320
}
303321

322+
func (a *ContractAddressChange) IsClientRequest() bool {
323+
return false
324+
}
325+
304326
func (a *BodyOfAgreementOffer) Code() string {
305327
return CodeBodyOfAgreementOffer
306328
}
@@ -309,6 +331,10 @@ func (a *BodyOfAgreementOffer) TypeName() string {
309331
return "BodyOfAgreementOffer"
310332
}
311333

334+
func (a *BodyOfAgreementOffer) IsClientRequest() bool {
335+
return true
336+
}
337+
312338
func (a *BodyOfAgreementFormation) Code() string {
313339
return CodeBodyOfAgreementFormation
314340
}
@@ -317,6 +343,10 @@ func (a *BodyOfAgreementFormation) TypeName() string {
317343
return "BodyOfAgreementFormation"
318344
}
319345

346+
func (a *BodyOfAgreementFormation) IsClientRequest() bool {
347+
return false
348+
}
349+
320350
func (a *BodyOfAgreementAmendment) Code() string {
321351
return CodeBodyOfAgreementAmendment
322352
}
@@ -325,6 +355,10 @@ func (a *BodyOfAgreementAmendment) TypeName() string {
325355
return "BodyOfAgreementAmendment"
326356
}
327357

358+
func (a *BodyOfAgreementAmendment) IsClientRequest() bool {
359+
return true
360+
}
361+
328362
func (a *InstrumentDefinition) Code() string {
329363
return CodeInstrumentDefinition
330364
}
@@ -333,6 +367,10 @@ func (a *InstrumentDefinition) TypeName() string {
333367
return "InstrumentDefinition"
334368
}
335369

370+
func (a *InstrumentDefinition) IsClientRequest() bool {
371+
return true
372+
}
373+
336374
func (a *InstrumentCreation) Code() string {
337375
return CodeInstrumentCreation
338376
}
@@ -341,6 +379,10 @@ func (a *InstrumentCreation) TypeName() string {
341379
return "InstrumentCreation"
342380
}
343381

382+
func (a *InstrumentCreation) IsClientRequest() bool {
383+
return false
384+
}
385+
344386
func (a *InstrumentModification) Code() string {
345387
return CodeInstrumentModification
346388
}
@@ -349,6 +391,10 @@ func (a *InstrumentModification) TypeName() string {
349391
return "InstrumentModification"
350392
}
351393

394+
func (a *InstrumentModification) IsClientRequest() bool {
395+
return true
396+
}
397+
352398
func (a *Transfer) Code() string {
353399
return CodeTransfer
354400
}
@@ -357,6 +403,10 @@ func (a *Transfer) TypeName() string {
357403
return "Transfer"
358404
}
359405

406+
func (a *Transfer) IsClientRequest() bool {
407+
return true
408+
}
409+
360410
func (a *Settlement) Code() string {
361411
return CodeSettlement
362412
}
@@ -365,6 +415,10 @@ func (a *Settlement) TypeName() string {
365415
return "Settlement"
366416
}
367417

418+
func (a *Settlement) IsClientRequest() bool {
419+
return false
420+
}
421+
368422
func (a *RectificationSettlement) Code() string {
369423
return CodeRectificationSettlement
370424
}
@@ -373,6 +427,10 @@ func (a *RectificationSettlement) TypeName() string {
373427
return "RectificationSettlement"
374428
}
375429

430+
func (a *RectificationSettlement) IsClientRequest() bool {
431+
return false
432+
}
433+
376434
func (a *Proposal) Code() string {
377435
return CodeProposal
378436
}
@@ -381,6 +439,10 @@ func (a *Proposal) TypeName() string {
381439
return "Proposal"
382440
}
383441

442+
func (a *Proposal) IsClientRequest() bool {
443+
return true
444+
}
445+
384446
func (a *Vote) Code() string {
385447
return CodeVote
386448
}
@@ -389,6 +451,10 @@ func (a *Vote) TypeName() string {
389451
return "Vote"
390452
}
391453

454+
func (a *Vote) IsClientRequest() bool {
455+
return false
456+
}
457+
392458
func (a *BallotCast) Code() string {
393459
return CodeBallotCast
394460
}
@@ -397,6 +463,10 @@ func (a *BallotCast) TypeName() string {
397463
return "BallotCast"
398464
}
399465

466+
func (a *BallotCast) IsClientRequest() bool {
467+
return true
468+
}
469+
400470
func (a *BallotCounted) Code() string {
401471
return CodeBallotCounted
402472
}
@@ -405,6 +475,10 @@ func (a *BallotCounted) TypeName() string {
405475
return "BallotCounted"
406476
}
407477

478+
func (a *BallotCounted) IsClientRequest() bool {
479+
return false
480+
}
481+
408482
func (a *Result) Code() string {
409483
return CodeResult
410484
}
@@ -413,6 +487,10 @@ func (a *Result) TypeName() string {
413487
return "Result"
414488
}
415489

490+
func (a *Result) IsClientRequest() bool {
491+
return false
492+
}
493+
416494
func (a *Order) Code() string {
417495
return CodeOrder
418496
}
@@ -421,6 +499,10 @@ func (a *Order) TypeName() string {
421499
return "Order"
422500
}
423501

502+
func (a *Order) IsClientRequest() bool {
503+
return true
504+
}
505+
424506
func (a *Freeze) Code() string {
425507
return CodeFreeze
426508
}
@@ -429,6 +511,10 @@ func (a *Freeze) TypeName() string {
429511
return "Freeze"
430512
}
431513

514+
func (a *Freeze) IsClientRequest() bool {
515+
return false
516+
}
517+
432518
func (a *Thaw) Code() string {
433519
return CodeThaw
434520
}
@@ -437,6 +523,10 @@ func (a *Thaw) TypeName() string {
437523
return "Thaw"
438524
}
439525

526+
func (a *Thaw) IsClientRequest() bool {
527+
return false
528+
}
529+
440530
func (a *Confiscation) Code() string {
441531
return CodeConfiscation
442532
}
@@ -445,6 +535,10 @@ func (a *Confiscation) TypeName() string {
445535
return "Confiscation"
446536
}
447537

538+
func (a *Confiscation) IsClientRequest() bool {
539+
return false
540+
}
541+
448542
func (a *DeprecatedReconciliation) Code() string {
449543
return CodeDeprecatedReconciliation
450544
}
@@ -453,6 +547,10 @@ func (a *DeprecatedReconciliation) TypeName() string {
453547
return "DeprecatedReconciliation"
454548
}
455549

550+
func (a *DeprecatedReconciliation) IsClientRequest() bool {
551+
return false
552+
}
553+
456554
func (a *Establishment) Code() string {
457555
return CodeEstablishment
458556
}
@@ -461,6 +559,10 @@ func (a *Establishment) TypeName() string {
461559
return "Establishment"
462560
}
463561

562+
func (a *Establishment) IsClientRequest() bool {
563+
return false
564+
}
565+
464566
func (a *Addition) Code() string {
465567
return CodeAddition
466568
}
@@ -469,6 +571,10 @@ func (a *Addition) TypeName() string {
469571
return "Addition"
470572
}
471573

574+
func (a *Addition) IsClientRequest() bool {
575+
return false
576+
}
577+
472578
func (a *Alteration) Code() string {
473579
return CodeAlteration
474580
}
@@ -477,6 +583,10 @@ func (a *Alteration) TypeName() string {
477583
return "Alteration"
478584
}
479585

586+
func (a *Alteration) IsClientRequest() bool {
587+
return false
588+
}
589+
480590
func (a *Removal) Code() string {
481591
return CodeRemoval
482592
}
@@ -485,6 +595,10 @@ func (a *Removal) TypeName() string {
485595
return "Removal"
486596
}
487597

598+
func (a *Removal) IsClientRequest() bool {
599+
return false
600+
}
601+
488602
func (a *Message) Code() string {
489603
return CodeMessage
490604
}
@@ -493,6 +607,10 @@ func (a *Message) TypeName() string {
493607
return "Message"
494608
}
495609

610+
func (a *Message) IsClientRequest() bool {
611+
return false
612+
}
613+
496614
func (a *Rejection) Code() string {
497615
return CodeRejection
498616
}
@@ -501,6 +619,10 @@ func (a *Rejection) TypeName() string {
501619
return "Rejection"
502620
}
503621

622+
func (a *Rejection) IsClientRequest() bool {
623+
return false
624+
}
625+
504626
// Formation creates a contract formation with all the values from the contract offer.
505627
func (a *ContractOffer) Formation() (*ContractFormation, error) {
506628
return &ContractFormation{

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/spf13/cobra v0.0.5
1111
github.com/tokenized/bitcoin_interpreter v0.1.1
1212
github.com/tokenized/envelope v1.1.0
13+
github.com/tokenized/logger v0.1.3
1314
github.com/tokenized/pkg v0.7.1-0.20230728163803-9a855fa7d049
1415
github.com/tokenized/txbuilder v1.1.1-0.20230816003850-4414c86d5db4
1516
golang.org/x/crypto v0.8.0
@@ -27,7 +28,6 @@ require (
2728
github.com/inconshreveable/mousetrap v1.0.0 // indirect
2829
github.com/spf13/pflag v1.0.3 // indirect
2930
github.com/tokenized/channels v0.1.1 // indirect
30-
github.com/tokenized/logger v0.1.3 // indirect
3131
github.com/tokenized/threads v0.1.2 // indirect
3232
github.com/tyler-smith/go-bip32 v0.0.0-20170922074101-2c9cfd177564 // indirect
3333
)

internal/golang/templates/actions.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ type Action interface {
1515
Code() string
1616
TypeName() string
1717
18+
// IsClientRequest returns true when this action is a client request to a smart contract agent.
19+
IsClientRequest() bool
20+
1821
Validate() error
1922
Equal(proto.Message) bool
2023
}
@@ -128,6 +131,15 @@ func (a *{{.Name}}) Code() string {
128131
func (a *{{.Name}}) TypeName() string {
129132
return "{{.Name}}"
130133
}
134+
135+
// IsClientRequest returns true when this action is a client request to a smart contract agent.
136+
func (a *{{.Name}}) IsClientRequest() bool {
137+
{{- if eq (len .MetaData.Validation) 0 }}
138+
return false
139+
{{- else }}
140+
return true
141+
{{- end }}
142+
}
131143
{{ end }}
132144

133145
{{- range $i, $message := .Messages }}

0 commit comments

Comments
 (0)