func (server *RPCServer) ResyncBitcoin(args rpcmessages.AuthGenericRequest, reply *rpcmessages.ErrorResponse) error {
	err := server.middleware.ValidateToken(args.Token)
	if err != nil {
		*reply = server.formulateJWTError("ResyncBitcoin")
		return nil
	}
	*reply = server.middleware.ResyncBitcoin()
	log.Printf("RPCServer sent reply for the %q RPC: %+v\n", "ResyncBitcoin", reply)
	return nil
}
ResyncBitcoin sends the middleware's ErrorResponse over rpc
package rpcserver
import (
	"log"
	"net/rpc"
	"github.com/digitalbitbox/bitbox-base/middleware/src/rpcmessages"
)
type rpcConn struct {
	readChan  chan []byte
	writeChan chan []byte
}
func newRPCConn() *rpcConn {
	RPCConn := &rpcConn{
		readChan:  make(chan []byte),
		writeChan: make(chan []byte),
	}
	return RPCConn
}
func (conn *rpcConn) ReadChan() chan []byte {
	return conn.readChan
}
func (conn *rpcConn) WriteChan() chan []byte {
	return conn.writeChan
}
func (conn *rpcConn) Read(p []byte) (n int, err error) {
	message := <-conn.readChan
	return copy(p, message), nil
}
func (conn *rpcConn) Write(p []byte) (n int, err error) {
	conn.writeChan <- append([]byte(rpcmessages.OpRPCCall), p...)
	return len(p), nil
}
func (conn *rpcConn) Close() error {
	return nil
}
type Middleware interface {
	BackupHSMSecret() rpcmessages.ErrorResponse
	BackupSysconfig() rpcmessages.ErrorResponse
	EnableClearnetIBD(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableRootLogin(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableSSHPasswordLogin(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTor(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorElectrs(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorMiddleware(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	EnableTorSSH(rpcmessages.ToggleSettingArgs) rpcmessages.ErrorResponse
	FinalizeSetupWizard() rpcmessages.ErrorResponse
	GetBaseInfo() rpcmessages.GetBaseInfoResponse
	GetBaseUpdateProgress() rpcmessages.GetBaseUpdateProgressResponse
	GetServiceInfo() rpcmessages.GetServiceInfoResponse
	GetServiceStatus() rpcmessages.GetServiceStatusResponse
	IsBaseUpdateAvailable() rpcmessages.IsBaseUpdateAvailableResponse
	RebootBase() rpcmessages.ErrorResponse
	ReindexBitcoin() rpcmessages.ErrorResponse
	RestoreHSMSecret() rpcmessages.ErrorResponse
	RestoreSysconfig() rpcmessages.ErrorResponse
	ResyncBitcoin() rpcmessages.ErrorResponse
	SetHostname(rpcmessages.SetHostnameArgs) rpcmessages.ErrorResponse
	SetLoginPassword(rpcmessages.SetLoginPasswordArgs) rpcmessages.ErrorResponse
	SetupStatus() rpcmessages.SetupStatusResponse
	ShutdownBase() rpcmessages.ErrorResponse
	SystemEnv() rpcmessages.GetEnvResponse
	UpdateBase(rpcmessages.UpdateBaseArgs) rpcmessages.ErrorResponse
	UserAuthenticate(rpcmessages.UserAuthenticateArgs) rpcmessages.UserAuthenticateResponse
	UserChangePassword(rpcmessages.UserChangePasswordArgs) rpcmessages.ErrorResponse
	ValidateToken(token string) error
}
type RPCServer struct {
	middleware    Middleware
	RPCConnection *rpcConn
}
func NewRPCServer(middleware Middleware) *RPCServer {
	server := &RPCServer{
		middleware: middleware,
		RPCConnection: newRPCConn(),
	}
	err := rpc.Register(server)
	if err != nil {
		log.Println("Unable to register new rpc server")
	}
	return server
}
func (server *RPCServer) Serve(dummyArg bool, dummyPointer *bool) error {
	rpc.ServeConn(server.RPCConnection)
	return nil
}
func (server *RPCServer) formulateJWTError(name string) rpcmessages.ErrorResponse {
	log.Printf("received rpc request to %s with invalid json web token", name)
	return rpcmessages.ErrorResponse{
		Success: false,
		Message: "JSON web token validation failed",
		Code:    rpcmessages.JSONWebTokenInvalid,
	}
}
func (server *RPCServer) GetSetupStatus(dummyArg bool, reply *rpcmessages.SetupStatusResponse) error {
	*reply = server.middleware.SetupStatus()
	log.Printf("RPCServer sent reply for the %q RPC: %+v\n", "GetSetupStatus", reply)
	return nil
}
func (server *RPCServer) GetSystemEnv(args rpcmessages.AuthGenericRequest, reply *rpcmessages.GetEnvResponse) error {
	err := server.middleware.ValidateToken(args.Token)
	if err != nil {
		*reply = rpcmessages.GetEnvResponse{}
		log.Printf("received rpc request to GetSystemEnv with invalid json web token")
		return nil
	}
	*reply = server.middleware.SystemEnv()
	log.Printf("RPCServer sent reply for the %q RPC: %+v\n", "GetSystemEnv", reply)
	return nil
}
func (server *RPCServer) ReindexBitcoin(args rpcmessages.AuthGenericRequest, reply *rpcmessages.ErrorResponse) error {
	err := server.middleware.ValidateToken(args.Token)
	if err != nil {
		*reply = server.formulateJWTError("ReindexBitcoin")
		return nil
	}
	*reply = server.middleware.ReindexBitcoin()
	log.Printf("RPCServer sent reply for the %q RPC: %+v\n", "ReindexBitcoin", reply)
	return nil
}