certichain

Blockchain built from scratch for verifying document's legitimacy.
Log | Files | Refs | README | LICENSE

commit 8be34643e63c55bf8bc5507c733ae5670ecad434
parent c2a00254cff010e7c8e0679f36de439dfda66b35
Author: Shivakumar <[email protected]>
Date:   Thu, 13 Aug 2026 01:34:44 +0530

feat: add verify to certi command

Signed-off-by: Shivakumar <[email protected]>

Diffstat:
Mcmd/certi/main.go | 2++
Acmd/certi/verify.go | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/cmd/certi/main.go b/cmd/certi/main.go @@ -30,6 +30,8 @@ func main() { runInit(os.Args[2:]) case "anchor": runAnchor(os.Args[2:]) + case "verify": + runVerify(os.Args[2:]) default: fmt.Fprintf(os.Stderr, "unknown command: %s\n", os.Args[1]) os.Exit(1) diff --git a/cmd/certi/verify.go b/cmd/certi/verify.go @@ -0,0 +1,65 @@ +// Copyright 2026 Shivakumar (Certichain) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package main + +import ( + "encoding/json" + "flag" + "fmt" + "net/http" + "os" + + "certichain/api/dto" +) + +func runVerify(args []string) { + fs := flag.NewFlagSet("verify", flag.ExitOnError) + url := fs.String("url", "http://localhost:8080", "certichainn node base URL") + fs.Parse(args) + + if fs.NArg() != 1 { + fmt.Fprintln(os.Stderr, "usage: certi verify [flags] <tx-id>") + os.Exit(1) + } + txID := fs.Arg(0) + + resp, err := http.Get(*url + "/v1/verify/" + txID) + if err != nil { + fmt.Fprintln(os.Stderr, "contacting node:", err) + os.Exit(1) + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + var errResp dto.ErrorResponse + json.NewDecoder(resp.Body).Decode(&errResp) + fmt.Fprintf(os.Stderr, "verification failed: %s - %s", errResp.Error.Code, errResp.Error.Message) + os.Exit(1) + } + + var verifyResp dto.VerifyResponse + if err := json.NewDecoder(resp.Body).Decode(&verifyResp); err != nil { + fmt.Fprintln(os.Stderr, "decoding response:", err) + os.Exit(1) + } + + pretty, err := json.MarshalIndent(verifyResp, "", " ") + if err != nil { + fmt.Fprintln(os.Stderr, "decoding response:", err) + os.Exit(1) + } + fmt.Fprint(os.Stdout, "Success: Valid Transaction\nResponse:\n") + fmt.Fprintln(os.Stdout, string(pretty)) +}