[#11] Use Neo:Morph ServiceExecutor of Accounting service in app

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-22 18:20:47 +03:00 committed by Alex Vanin
parent 5022362c1a
commit e6fedfbc69
4 changed files with 91 additions and 26 deletions

View file

@ -0,0 +1,51 @@
package main
import (
"github.com/nspcc-dev/neo-go/pkg/util"
accountingGRPC "github.com/nspcc-dev/neofs-api-go/v2/accounting/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/nspcc-dev/neofs-node/pkg/morph/client"
"github.com/nspcc-dev/neofs-node/pkg/morph/client/balance"
accountingTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/accounting/grpc"
accountingService "github.com/nspcc-dev/neofs-node/pkg/services/accounting"
accounting "github.com/nspcc-dev/neofs-node/pkg/services/accounting/morph"
)
type cfgAccounting struct {
scriptHash string
fee util.Fixed8
}
func initAccountingService(c *cfg) {
if c.morphClient == nil {
initMorphComponents(c)
}
u160, err := util.Uint160DecodeStringLE(c.cfgAccounting.scriptHash)
fatalOnErr(err)
staticClient, err := client.NewStatic(c.morphClient, u160, c.cfgAccounting.fee)
fatalOnErr(err)
balanceClient, err := balance.New(staticClient)
fatalOnErr(err)
metaHdr := new(session.ResponseMetaHeader)
xHdr := new(session.XHeader)
xHdr.SetKey("test X-Header key")
xHdr.SetValue("test X-Header value")
metaHdr.SetXHeaders([]*session.XHeader{xHdr})
accountingGRPC.RegisterAccountingServiceServer(c.grpcSrv,
accountingTransportGRPC.New(
accountingService.NewSignService(
c.key,
accountingService.NewExecutionService(
accounting.NewExecutor(balanceClient),
metaHdr,
),
),
),
)
}