From 32b89be7e538a7e6d77f331a2104fe1a110b499f Mon Sep 17 00:00:00 2001 From: michaelbeam Date: Tue, 2 Jun 2015 15:34:37 -0500 Subject: [PATCH] added testcredit factomapi and wsapi --- factomapi/api.go | 10 ++++++++++ wsapi/wsapi.go | 19 ++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/factomapi/api.go b/factomapi/api.go index 8b06a15..ec288e4 100644 --- a/factomapi/api.go +++ b/factomapi/api.go @@ -17,6 +17,16 @@ var ( inMsgQ chan wire.FtmInternalMsg ) +// TODO remove before production +func TestCredit(key []byte, amt int32) { + msg := wire.NewMsgTestCredit() + copy(msg.ECKey[:], key) + msg.Amt = amt + + inMsgQ <- msg +} + + func ChainHead(chainid string) (*common.EBlock, error) { h, err := atoh(chainid) if err != nil { diff --git a/wsapi/wsapi.go b/wsapi/wsapi.go index e016665..d73fc98 100644 --- a/wsapi/wsapi.go +++ b/wsapi/wsapi.go @@ -49,8 +49,9 @@ func Start(db database.Db, inMsgQ chan wire.FtmInternalMsg) { server.Get("/v1/chain-head/([^/]+)", handleChainHead) server.Get("/v1/entry-credit-balance/([^/]+)", handleEntryCreditBalance) - server.Get("/v1/test/?", handleTest) - + // TODO remove before production + server.Get("/v1/test-credit/([^/]+)", handleTestCredit) + wsLog.Info("Starting server") go server.Run("localhost:" + strconv.Itoa(portNumber)) } @@ -59,9 +60,17 @@ func Stop() { server.Close() } -func handleTest(ctx *web.Context) { - wsLog.Info("handleTest") - ctx.WriteString("hello") +// TODO remove before production +func handleTestCredit(ctx *web.Context, eckey string) { + p, err := hex.DecodeString(eckey) + if err != nil { + wsLog.Error(err) + ctx.WriteHeader(httpBad) + return + } + + factomapi.TestCredit(p, 100) + ctx.WriteHeader(httpOK) } func handleCommitChain(ctx *web.Context) {