Skip to content

Commit 32b89be

Browse files
committed
added testcredit factomapi and wsapi
1 parent ecba9c6 commit 32b89be

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

factomapi/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ var (
1717
inMsgQ chan wire.FtmInternalMsg
1818
)
1919

20+
// TODO remove before production
21+
func TestCredit(key []byte, amt int32) {
22+
msg := wire.NewMsgTestCredit()
23+
copy(msg.ECKey[:], key)
24+
msg.Amt = amt
25+
26+
inMsgQ <- msg
27+
}
28+
29+
2030
func ChainHead(chainid string) (*common.EBlock, error) {
2131
h, err := atoh(chainid)
2232
if err != nil {

wsapi/wsapi.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ func Start(db database.Db, inMsgQ chan wire.FtmInternalMsg) {
4949
server.Get("/v1/chain-head/([^/]+)", handleChainHead)
5050
server.Get("/v1/entry-credit-balance/([^/]+)", handleEntryCreditBalance)
5151

52-
server.Get("/v1/test/?", handleTest)
53-
52+
// TODO remove before production
53+
server.Get("/v1/test-credit/([^/]+)", handleTestCredit)
54+
5455
wsLog.Info("Starting server")
5556
go server.Run("localhost:" + strconv.Itoa(portNumber))
5657
}
@@ -59,9 +60,17 @@ func Stop() {
5960
server.Close()
6061
}
6162

62-
func handleTest(ctx *web.Context) {
63-
wsLog.Info("handleTest")
64-
ctx.WriteString("hello")
63+
// TODO remove before production
64+
func handleTestCredit(ctx *web.Context, eckey string) {
65+
p, err := hex.DecodeString(eckey)
66+
if err != nil {
67+
wsLog.Error(err)
68+
ctx.WriteHeader(httpBad)
69+
return
70+
}
71+
72+
factomapi.TestCredit(p, 100)
73+
ctx.WriteHeader(httpOK)
6574
}
6675

6776
func handleCommitChain(ctx *web.Context) {

0 commit comments

Comments
 (0)