-
Notifications
You must be signed in to change notification settings - Fork 0
/
svc_dapp.go
63 lines (52 loc) · 1.7 KB
/
svc_dapp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package service
import (
"dapp/lib"
"dapp/repo"
"dapp/schema"
"dapp/schema/dto"
"dapp/schema/mapper"
"github.com/kataras/iris/v12"
)
// region ======== SETUP =================================================================
// ISvcDapp Dapp request service interface
type ISvcDapp interface {
Query(query dto.Transaction, did string) (interface{}, *dto.Problem)
Invoke(req dto.Transaction, did string) (interface{}, *dto.Problem)
}
type svcDapp struct {
repoDapp *repo.RepoDapp
}
// endregion =============================================================================
// NewSvcDappReqs instantiate the Dapp request services
func NewSvcDappReqs(repoDapp *repo.RepoDapp) ISvcDapp {
return &svcDapp{repoDapp}
}
// region ======== METHODS ======================================================
func (s *svcDapp) Query(query dto.Transaction, did string) (interface{}, *dto.Problem) {
// requesting blockchain ledger
raw, e := s.repoDapp.Query(query, did)
if e != nil {
return nil, lib.NewProblem(iris.StatusBadGateway, schema.ErrBlockchainTxs, e.Error())
}
result := mapper.DecodePayload(raw)
return result, nil
}
func (s *svcDapp) Invoke(req dto.Transaction, did string) (interface{}, *dto.Problem) {
// requesting blockchain ledger
result, e := (*s.repoDapp).Invoke(req, did)
if e != nil {
return nil, lib.NewProblem(iris.StatusBadGateway, schema.ErrBlockchainTxs, e.Error())
}
dPayload := mapper.DecodePayload(result)
qResult := dto.TxReceipt{
ReplyCommon: dto.ReplyCommon{Headers: dto.ReplyHeaders{
CommonHeaders: req.Headers.CommonHeaders,
Received: "",
Elapsed: 0,
ReqOffset: "",
ReqID: "",
}},
ResponsePayload: dPayload,
}
return qResult, nil
}