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/certificate/funcs.go b/src/certificate/funcs.go index 30424d9..2d50865 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.Marshal(bc) + _ = ioutil.WriteFile(srcFile, fileDat, 0644) +} func FileByteOut(srcFile string) []byte { data, err := ioutil.ReadFile(srcFile) if err != nil { diff --git a/src/p2p/funcs.go b/src/p2p/funcs.go index 86ae9fc..b9cdd5a 100644 --- a/src/p2p/funcs.go +++ b/src/p2p/funcs.go @@ -270,6 +270,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)