From 3b2ed5ea6b3baea35c43af234f85edc21cabd598 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Wed, 30 Jun 2021 12:25:47 +0530 Subject: [PATCH 1/3] Added storing to json --- src/certificate/funcs.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/certificate/funcs.go b/src/certificate/funcs.go index 30424d9..ff48be5 100644 --- a/src/certificate/funcs.go +++ b/src/certificate/funcs.go @@ -4,6 +4,7 @@ import ( "crypto/rsa" "crypto/sha256" "encoding/hex" + "encoding/json" "fmt" "io/ioutil" "strings" @@ -12,6 +13,10 @@ import ( "github.com/panzerox123/blockcert/src/keygen" ) +func (bc *BlockChain) SaveToJson(srcFile string) { + fileDat, _ := json.MarshalIndent(bc, "", " ") + _ = ioutil.WriteFile(srcFile, fileDat, 0644) +} func FileByteOut(srcFile string) []byte { data, err := ioutil.ReadFile(srcFile) if err != nil { From ada7ef3dad920406aa60000466d754ba3edc0558 Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Wed, 30 Jun 2021 13:05:34 +0530 Subject: [PATCH 2/3] Saving to Json --- src/p2p/funcs.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/p2p/funcs.go b/src/p2p/funcs.go index 96a7902..811fe87 100644 --- a/src/p2p/funcs.go +++ b/src/p2p/funcs.go @@ -258,6 +258,9 @@ func (node *P2pNode) VerifyChain() bool { fmt.Println(val) return val } +func (node *P2pNode) bcToJson(srcFile string) { + node.blockchain.SaveToJson(srcFile) +} func (node *P2pNode) CheckCertificate(data []byte, pubkey *rsa.PublicKey) bool { return node.blockchain.CheckSignature(data, pubkey) From 95a8078ea322afc22e25ae196c04ddbe71f6847d Mon Sep 17 00:00:00 2001 From: Utkarsh Gupta Date: Wed, 30 Jun 2021 13:07:07 +0530 Subject: [PATCH 3/3] saving to json --- blockcert.go | 1 + src/p2p/funcs.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/blockcert.go b/blockcert.go index 4db869f..0331d93 100644 --- a/blockcert.go +++ b/blockcert.go @@ -32,6 +32,7 @@ func shell(ctx context.Context, node *p2p.P2pNode) { //privateKey := keygen.ParsePrivateRSA(cli_args[2]) node.NewCertPublisher(ctx, cli_args[1], cli_args[2]) fmt.Println("Certificate successfully added!") + node.BcToJson(cli_args[3]) case "showallcerts": node.ShowBlocks() case "peers": diff --git a/src/p2p/funcs.go b/src/p2p/funcs.go index 811fe87..0ba4908 100644 --- a/src/p2p/funcs.go +++ b/src/p2p/funcs.go @@ -258,7 +258,7 @@ func (node *P2pNode) VerifyChain() bool { fmt.Println(val) return val } -func (node *P2pNode) bcToJson(srcFile string) { +func (node *P2pNode) BcToJson(srcFile string) { node.blockchain.SaveToJson(srcFile) }