dto.go (3452B)
1 // Copyright 2026 Shivakumar (Certichain) 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package dto 16 17 // Institution DTOs 18 19 // RegisterInstitutionRequest is the request body for POST /v1/institutions. 20 type RegisterInstitutionRequest struct { 21 PublicKey string `json:"public_key"` 22 } 23 24 // RegisterInstitutionResponse is returned after a successful registration. 25 type RegisterInstitutionResponse struct { 26 DID string `json:"did"` 27 } 28 29 // GetInstitutionResponse is returned by GET /v1/institutions/{did}. 30 type GetInstitutionResponse struct { 31 DID string `json:"did"` 32 Registered bool `json:"registered"` 33 } 34 35 // Transaction DTOs 36 37 // SubmitTransactionRequest is the request body for POST /v1/transactions. 38 type SubmitTransactionRequest struct { 39 TxID string `json:"tx_id"` 40 IssuerDID string `json:"issuer_did"` 41 MerkleRoot string `json:"merkle_root"` 42 Nonce string `json:"nonce"` 43 Timestamp int64 `json:"timestamp"` 44 Signature string `json:"signature"` 45 } 46 47 // SubmitTransactionResponse is returned after a transaction is accepted into the mempool. 48 // Status is always "pending" at this point. 49 type SubmitTransactionResponse struct { 50 TxID string `json:"tx_id"` 51 Status string `json:"status"` 52 } 53 54 // GetTransactionResponse is returned by GET /v1/transactions/{tx_id}. 55 type GetTransactionResponse struct { 56 TxID string `json:"tx_id"` 57 IssuerDID string `json:"issuer_did"` 58 MerkleRoot string `json:"merkle_root"` 59 Timestamp string `json:"timestamp"` 60 Status string `json:"status"` // "pending" or "confirmed" 61 BlockHash *string `json:"block_hash,omitempty"` // only persent if "confirmed" 62 } 63 64 // Block DTO 65 66 // BlockResponse is returned by the block query endpoints. 67 // (GET /v1/blocks/{hash}, /v1/blocks/height/{height}, /v1/blocks/latest). 68 type BlockResponse struct { 69 Height uint64 `json:"height"` 70 Hash string `json:"hash"` 71 PrevHash string `json:"prev_hash"` 72 MerkleRoot string `json:"merkle_root"` 73 Timestamp string `json:"timestamp"` 74 Transactions []GetTransactionResponse `json:"transactions"` 75 } 76 77 // Verify DTO 78 79 // VerifyResponse is returned by GET /v1/verify/{tx_id}. 80 type VerifyResponse struct { 81 TxID string `json:"tx_id"` 82 IssuerDID string `json:"issuer_did"` 83 IssuerPublicKey string `json:"issuer_public_key"` 84 MerkleRoot string `json:"merkle_root"` 85 BlockHash string `json:"block_hash"` 86 BlockHeight uint64 `json:"block_height"` 87 BlockMerkleRoot string `json:"block_merkle_root"` 88 Timestamp string `json:"timestamp"` 89 } 90 91 // Shared Error Envelope 92 93 // ErrorDetail carries error code and readable message string. 94 type ErrorDetail struct { 95 Code string `json:"code"` 96 Message string `json:"message"` 97 } 98 99 // ErrorResponse is the JSON Envelop for every NON-2XX http response. 100 type ErrorResponse struct { 101 Error ErrorDetail `json:"error"` 102 }