[#11] services/container: Implement Neo:Morph executor and service

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-24 17:07:08 +03:00 committed by Alex Vanin
parent 9e30a87022
commit 8539f5c2cd
6 changed files with 458 additions and 3 deletions

View file

@ -24,6 +24,8 @@ type cfg struct {
cfgMorph cfgMorph
cfgAccounting cfgAccounting
cfgContainer cfgContainer
}
type cfgGRPC struct {
@ -46,6 +48,12 @@ type cfgAccounting struct {
fee util.Fixed8
}
type cfgContainer struct {
scriptHash string
fee util.Fixed8
}
func defaultCfg() *cfg {
key, err := crypto.LoadPrivateKey("Kwk6k2eC3L3QuPvD8aiaNyoSXgQ2YL1bwS5CP1oKoA9waeAze97s")
fatalOnErr(err)
@ -64,5 +72,9 @@ func defaultCfg() *cfg {
scriptHash: "1aeefe1d0dfade49740fff779c02cd4a0538ffb1",
fee: util.Fixed8(1),
},
cfgContainer: cfgContainer{
scriptHash: "9d2ca84d7fb88213c4baced5a6ed4dc402309039",
fee: util.Fixed8(1),
},
}
}

View file

@ -0,0 +1,41 @@
package main
import (
"github.com/nspcc-dev/neo-go/pkg/util"
containerGRPC "github.com/nspcc-dev/neofs-api-go/v2/container/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/container"
containerTransportGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
containerService "github.com/nspcc-dev/neofs-node/pkg/services/container"
containerMorph "github.com/nspcc-dev/neofs-node/pkg/services/container/morph"
)
func initContainerService(c *cfg) {
u160, err := util.Uint160DecodeStringLE(c.cfgContainer.scriptHash)
fatalOnErr(err)
staticClient, err := client.NewStatic(c.cfgMorph.client, u160, c.cfgContainer.fee)
fatalOnErr(err)
cnrClient, err := container.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})
containerGRPC.RegisterContainerServiceServer(c.cfgGRPC.server,
containerTransportGRPC.New(
containerService.NewSignService(
c.key,
containerService.NewExecutionService(
containerMorph.NewExecutor(cnrClient),
metaHdr,
),
),
),
)
}

View file

@ -4,10 +4,8 @@ import (
"fmt"
"log"
container "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
containerGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/container/grpc"
objectGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/object/grpc"
sessionGRPC "github.com/nspcc-dev/neofs-node/pkg/network/transport/session/grpc"
"github.com/nspcc-dev/neofs-node/pkg/util/grace"
@ -37,8 +35,8 @@ func init_(c *cfg) {
initGRPC(c)
initAccountingService(c)
initContainerService(c)
container.RegisterContainerServiceServer(c.cfgGRPC.server, containerGRPC.New(new(containerSvc)))
session.RegisterSessionServiceServer(c.cfgGRPC.server, sessionGRPC.New(new(sessionSvc)))
object.RegisterObjectServiceServer(c.cfgGRPC.server, objectGRPC.New(new(objectSvc)))
}