Skip to content

Commit

Permalink
added testcredit factomapi and wsapi
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbeam committed Jun 2, 2015
1 parent ecba9c6 commit 32b89be
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
10 changes: 10 additions & 0 deletions factomapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 14 additions & 5 deletions wsapi/wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand All @@ -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) {
Expand Down

0 comments on commit 32b89be

Please sign in to comment.