Skip to content

Commit 754107c

Browse files
committed
Added get-raw-data api
1 parent f964c1c commit 754107c

2 files changed

Lines changed: 61 additions & 3 deletions

File tree

database/ldb/dbtest/dbtst.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type tst struct {
1717
value string
1818
}
1919

20-
const dbpath = "/tmp/ldb9"
20+
const dbpath = "/tmp/ldb"
2121

2222
func main() {
2323

@@ -53,7 +53,7 @@ func main() {
5353
elice = append(elice, t)
5454

5555
}
56-
56+
5757
fmt.Printf("len(elice):%v", len(elice))
5858
fmt.Printf("completed\n")
5959
ldb.Close()

wsapi/wsapi.go

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,15 @@ func Start(db database.Db, inMsgQ chan wire.FtmInternalMsg) {
5555
server.Post("/v1/reveal-entry/?", handleRevealEntry)
5656
server.Post("/v1/factoid-submit/?", handleFactoidSubmit)
5757
server.Get("/v1/directory-block-head/?", handleDirectoryBlockHead)
58+
server.Get("/v1/get-raw-data/([^/]+)", handleGetRaw)
5859
server.Get("/v1/directory-block-by-keymr/([^/]+)", handleDirectoryBlock)
5960
server.Get("/v1/entry-block-by-keymr/([^/]+)", handleEntryBlock)
6061
server.Get("/v1/entry-by-hash/([^/]+)", handleEntry)
6162
server.Get("/v1/chain-head/([^/]+)", handleChainHead)
6263
server.Get("/v1/entry-credit-balance/([^/]+)", handleEntryCreditBalance)
6364
server.Get("/v1/factoid-balance/([^/]+)", handleFactoidBalance)
6465
server.Get("/v1/factoid-get-fee/", handleGetFee)
66+
6567

6668
wsLog.Info("Starting server")
6769
go server.Run("localhost:" + strconv.Itoa(portNumber))
@@ -249,7 +251,7 @@ func handleDirectoryBlock(ctx *web.Context, keymr string) {
249251
}
250252
EntryBlockList []eblockaddr
251253
}
252-
254+
253255
d := new(dblock)
254256
if block, err := factomapi.DBlockByKeyMR(keymr); err != nil {
255257
wsLog.Error(err)
@@ -517,3 +519,59 @@ func handleGetFee(ctx *web.Context) {
517519
ctx.Write(p)
518520
}
519521
}
522+
523+
524+
func handleGetRaw(ctx *web.Context, hashkey string) {
525+
type rawData struct {
526+
Data string
527+
}
528+
//TODO: var block common.BinaryMarshallable
529+
d := new(rawData)
530+
531+
h, err := common.HexToHash(hashkey);
532+
if err != nil {
533+
wsLog.Error(err)
534+
ctx.WriteHeader(httpBad)
535+
ctx.Write([]byte(err.Error()))
536+
return
537+
}
538+
539+
// try to find the block data in db and return the first one found
540+
if block, _ := dbase.FetchFBlockByHash(h); block !=nil {
541+
bytes, _ := block.MarshalBinary()
542+
d.Data = hex.EncodeToString(bytes[:])
543+
} else if block, _ := dbase.FetchDBlockByHash(h); block !=nil {
544+
bytes, _ := block.MarshalBinary()
545+
d.Data = hex.EncodeToString(bytes[:])
546+
} else if block, _ := dbase.FetchABlockByHash(h); block !=nil {
547+
bytes, _ := block.MarshalBinary()
548+
d.Data = hex.EncodeToString(bytes[:])
549+
} else if block, _ := dbase.FetchDBlockByMR(h); block !=nil {
550+
bytes, _ := block.MarshalBinary()
551+
d.Data = hex.EncodeToString(bytes[:])
552+
} else if block, _ := dbase.FetchEBlockByHash(h); block !=nil {
553+
bytes, _ := block.MarshalBinary()
554+
d.Data = hex.EncodeToString(bytes[:])
555+
} else if block, _ := dbase.FetchEBlockByMR(h); block !=nil {
556+
bytes, _ := block.MarshalBinary()
557+
d.Data = hex.EncodeToString(bytes[:])
558+
} else if block, _ := dbase.FetchECBlockByHash(h); block !=nil {
559+
bytes, _ := block.MarshalBinary()
560+
d.Data = hex.EncodeToString(bytes[:])
561+
} else if block, _ := dbase.FetchEntryByHash(h); block !=nil {
562+
bytes, _ := block.MarshalBinary()
563+
d.Data = hex.EncodeToString(bytes[:])
564+
}
565+
566+
567+
if p, err := json.Marshal(d); err != nil {
568+
wsLog.Error(err)
569+
ctx.WriteHeader(httpBad)
570+
ctx.Write([]byte(err.Error()))
571+
return
572+
} else {
573+
ctx.Write(p)
574+
}
575+
576+
// ctx.WriteHeader(httpOK)
577+
}

0 commit comments

Comments
 (0)