From c038d6b27e110442c984a64cd1d587960fd42ec2 Mon Sep 17 00:00:00 2001 From: George Tankersley Date: Wed, 22 May 2019 16:22:23 -0400 Subject: [PATCH] WIP: transaction sending; should be z_sendmany --- swag/server.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/swag/server.go b/swag/server.go index 0b9377e..48566fa 100644 --- a/swag/server.go +++ b/swag/server.go @@ -11,14 +11,67 @@ type Server struct { } func NewServer(dbPath string, zc *rpcclient.Client) (api.SwagAPIServer, error) { + // TODO: CREATE AND POPULATE THE DATABASE return &Server{}, nil } func (s *Server) Redeem(ctx context.Context, req *api.Request) (*api.Response, error) { + + // TODO: QUERY THE DATABASE + + // TODO: SEND THE TRANSACTION IN RESPONSE + return &api.Response{ Success: true, - Msg: "hello", + Msg: "", }, nil } func (s *Server) GracefulStop() {} + +// SendTransaction forwards raw transaction bytes to a zcashd instance over JSON-RPC +//func (s *Server) SendTransaction(ctx context.Context, rawtx *walletrpc.RawTransaction) (*walletrpc.SendResponse, error) { +// // sendrawtransaction "hexstring" ( allowhighfees ) +// // +// // Submits raw transaction (serialized, hex-encoded) to local node and network. +// // +// // Also see createrawtransaction and signrawtransaction calls. +// // +// // Arguments: +// // 1. "hexstring" (string, required) The hex string of the raw transaction) +// // 2. allowhighfees (boolean, optional, default=false) Allow high fees +// // +// // Result: +// // "hex" (string) The transaction hash in hex + +// // Construct raw JSON-RPC params +// params := make([]json.RawMessage, 1) +// txHexString := hex.EncodeToString(rawtx.Data) +// params[0] = json.RawMessage("\"" + txHexString + "\"") +// result, rpcErr := s.client.RawRequest("sendrawtransaction", params) + +// var err error +// var errCode int64 +// var errMsg string + +// // For some reason, the error responses are not JSON +// if rpcErr != nil { +// errParts := strings.SplitN(rpcErr.Error(), ":", 2) +// errMsg = strings.TrimSpace(errParts[1]) +// errCode, err = strconv.ParseInt(errParts[0], 10, 32) +// if err != nil { +// // This should never happen. We can't panic here, but it's that class of error. +// // This is why we need integration testing to work better than regtest currently does. TODO. +// return nil, errors.New("SendTransaction couldn't parse error code") +// } +// } else { +// errMsg = string(result) +// } + +// // TODO these are called Error but they aren't at the moment. +// // A success will return code 0 and message txhash. +// return &walletrpc.SendResponse{ +// ErrorCode: int32(errCode), +// ErrorMessage: errMsg, +// }, nil +//}