rvasp

package
v1.0.0-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 27, 2022 License: MIT Imports: 37 Imported by: 0

README

rVASP

Robot VASP for TRISA demonstration and integration

This is a simple gRPC server that implements a UI workflow and messaging framework to demonstrate sending and receiving transactions using the TRISA InterVASP protocol. The server was built to support a demonstration UI that requires a streaming interface so that a live message flow is achieved. However, the communication protocol between rVASPs also demonstrates how implementers might go about writing InterVASP services in their own codebases. The architecture is as follows:

Architecture

Generating Protocol Buffers

To regenerate the Go and Python code from the protocol buffers:

$ go generate ./...

This will generate the Go code in pb/ and the Python code in pb/rvaspy. Alternatively you can manually generate the code to specify different directories using the following commands:

$ protoc -I . --go_out=plugins=grpc:. api.proto
$ python -m grpc_tools.protoc -I . --python_out=./rvaspy --grpc_python_out=./rvaspy api.proto

Quick Start

To get started using the rVASP, you can run the local server as follows:

$ go run ./cmd/rvasp serve

The server should now be listening for TRISADemo RPC messages. To send messages using the python API, make sure you can import the modules from rvaspy - the simplest way to do this is to install the package in editable mode as follows:

$ pip install -e ./rvaspy/

This will use the setup.py file in the rvaspy directory to install the package to your $PYTHON_PATH. Because it is in editable mode, any time you regenerate the protocol buffers or pull the repository, the module should be updated on the next time you import. An example script for using the package is as follows:

import rvaspy

api = rvaspy.connect("localhost:4434")

cmds = [
    api.account_request("robert@bobvasp.co.uk"),
    api.transfer_request("robert@bobvasp.co.uk", "mary@alicevasp.us", 42.99)
]

for msg in api.stub.LiveUpdates(iter(cmds)):
    print(msg)

Note that the RVASP api client is not fully implemented yet.

Containers

We are currently not using a container repository, so to build the docker images locally, please run the following steps in order:

  1. Build the root Docker image tagged as trisacrypto/rvasp:latest
  2. Build the alice, bob, and evil containers in containers/, tagging them appropriately
  3. Use docker-compose to run the three rVASPs locally

To simplify the build process, we have added a script that builds all 4 images. You can execute the building script as follows:

$ ./containers/rebuild.sh

Then all that's needed is to run docker-compose up to get the robot VASPs running locally.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	pb.UnimplementedTRISADemoServer
	pb.UnimplementedTRISAIntegrationServer
	// contains filtered or unexported fields
}

Server implements the GRPC TRISAIntegration and TRISADemo services.

func New

func New(conf *config.Config) (s *Server, err error)

New creates a rVASP server with the specified configuration and prepares it to listen for and serve GRPC requests.

func (*Server) AccountStatus

func (s *Server) AccountStatus(ctx context.Context, req *pb.AccountRequest) (rep *pb.AccountReply, err error)

AccountStatus is a demo RPC to allow demo clients to fetch their recent transactions.

func (*Server) LiveUpdates

func (s *Server) LiveUpdates(stream pb.TRISADemo_LiveUpdatesServer) (err error)

LiveUpdates is a demo bidirectional RPC that allows demo clients to explicitly show the message interchange between VASPs during the InterVASP protocol. The demo client connects to both sides of a transaction and can push commands to the stream; any messages received by the VASP as they perform the protocol are sent down to the UI.

func (*Server) Serve

func (s *Server) Serve() (err error)

Serve GRPC requests on the specified address.

func (*Server) Shutdown

func (s *Server) Shutdown() (err error)

Shutdown the rVASP Service gracefully

func (*Server) Transfer

func (s *Server) Transfer(ctx context.Context, req *pb.TransferRequest) (*pb.TransferReply, error)

Transfer accepts a transfer request from a beneficiary and begins the InterVASP protocol to perform identity verification prior to establishing the transaction in the blockchain between crypto wallet addresses.

type TRISA

type TRISA struct {
	protocol.UnimplementedTRISANetworkServer
	protocol.UnimplementedTRISAHealthServer
	// contains filtered or unexported fields
}

TRISA implements the GRPC TRISANetwork and TRISAHealth services.

func NewTRISA

func NewTRISA(parent *Server) (svc *TRISA, err error)

NewTRISA from a parent server.

func (*TRISA) AsyncHandler added in v1.0.0

func (s *TRISA) AsyncHandler(stop <-chan struct{})

AsyncHandler is a go routine that periodically reads pending messages off the rVASP database and initiates TRISA transfers back to the originator. This allows the rVASPs to simulate asynchronous transactions.

func (*TRISA) ConfirmAddress

func (s *TRISA) ConfirmAddress(ctx context.Context, in *protocol.Address) (out *protocol.AddressConfirmation, err error)

ConfirmAddress allows the rVASP to respond to proof-of-control requests.

func (*TRISA) KeyExchange

func (s *TRISA) KeyExchange(ctx context.Context, in *protocol.SigningKey) (out *protocol.SigningKey, err error)

KeyExchange facilitates signing key exchange between VASPs.

func (*TRISA) Serve

func (s *TRISA) Serve() (err error)

Serve initializes the GRPC server and returns any errors during intitialization, it then kicks off a go routine to handle requests. Not thread safe, should not be called multiple times.

func (*TRISA) Shutdown

func (s *TRISA) Shutdown() (err error)

Shutdown the TRISA server gracefully

func (*TRISA) Status

func (s *TRISA) Status(ctx context.Context, in *protocol.HealthCheck) (out *protocol.ServiceState, err error)

Status returns a directory health check status as online and requests half an hour checks.

func (*TRISA) Transfer

func (s *TRISA) Transfer(ctx context.Context, in *protocol.SecureEnvelope) (out *protocol.SecureEnvelope, err error)

Transfer enables a quick one-off transaction between peers.

func (*TRISA) TransferStream

func (s *TRISA) TransferStream(stream protocol.TRISANetwork_TransferStreamServer) (err error)

TransferStream allows for high-throughput transactions.

type UpdateManager

type UpdateManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

UpdateManager sends update messages to all connected clients.

func NewUpdateManager

func NewUpdateManager() *UpdateManager

NewUpdateManager creates a new update manager ready to work. For thread safety, this is the only object that can send messages on update streams.

func (*UpdateManager) Add

func (u *UpdateManager) Add(client string, stream pb.TRISADemo_LiveUpdatesServer) (err error)

Add a new client update stream.

func (*UpdateManager) Broadcast

func (u *UpdateManager) Broadcast(requestID uint64, update string, cat pb.MessageCategory) (err error)

Broadcast a message to all streams.

func (*UpdateManager) Del

func (u *UpdateManager) Del(client string)

Del an old client update stream. No-op if client odesn't exist.

func (*UpdateManager) Send

func (u *UpdateManager) Send(client string, msg *pb.Message) (err error)

Send a message to a specific stream

func (*UpdateManager) SendTransferError

func (u *UpdateManager) SendTransferError(client string, id uint64, err *pb.Error) error

SendTransferError to client

Directories

Path Synopsis
* Package jsonpb uses protojson (not the deprecated jsonpb module) to set defaults for * marshaling and unmarshaling rVASP protobuf messages to and from JSON format.
* Package jsonpb uses protojson (not the deprecated jsonpb module) to set defaults for * marshaling and unmarshaling rVASP protobuf messages to and from JSON format.
pb
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL