github.com/kaleido-io/firefly@v0.0.0-20210622132723-8b4b6aacb971/pkg/fftypes/transaction.go (about) 1 // Copyright © 2021 Kaleido, Inc. 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package fftypes 18 19 import ( 20 "crypto/sha256" 21 "encoding/json" 22 ) 23 24 type TransactionType = LowerCasedType 25 26 const ( 27 // TransactionTypeNone indicates no transaction should be used for this message/batch 28 TransactionTypeNone TransactionType = "none" 29 // TransactionTypeBatchPin represents a pinning transaction, that verifies the originator of the data, and sequences the event deterministically between parties 30 TransactionTypeBatchPin TransactionType = "batch_pin" 31 ) 32 33 // TransactionRef refers to a transaction, in other types 34 type TransactionRef struct { 35 Type TransactionType `json:"type"` 36 ID *UUID `json:"id,omitempty"` 37 } 38 39 // TransactionSubject is the hashable reason for the transaction was performed 40 type TransactionSubject struct { 41 Signer string `json:"signer"` // on-chain signing identity 42 Namespace string `json:"namespace,omitempty"` 43 Type TransactionType `json:"type"` 44 Reference *UUID `json:"reference,omitempty"` 45 } 46 47 func (t *TransactionSubject) Hash() *Bytes32 { 48 b, _ := json.Marshal(&t) 49 var b32 Bytes32 = sha256.Sum256(b) 50 return &b32 51 } 52 53 // Transaction represents (blockchain) transactions that were submitted by this 54 // node, with the correlation information to look them up on the underlying 55 // ledger technology 56 type Transaction struct { 57 ID *UUID `json:"id,omitempty"` 58 Hash *Bytes32 `json:"hash"` 59 Subject TransactionSubject `json:"subject"` 60 Sequence int64 `json:"sequence,omitempty"` 61 Created *FFTime `json:"created"` 62 Status OpStatus `json:"status"` 63 ProtocolID string `json:"protocolID,omitempty"` 64 Info JSONObject `json:"info,omitempty"` 65 }