Documentation
¶
Overview ¶
monorepo/cloud/comiccoin-authority/domain/mempooltx.go
monorepo/cloud/comiccoin-authority/domain/signedtx.go
monorepo/cloud/comiccoin-authority/domain/tx.go
Index ¶
- Constants
- Variables
- func ToNonFungibleTokenIDsArray(nftoks []*NonFungibleToken) []*big.Int
- func ToTokenIDsArray(toks []*Token) []*big.Int
- func VerifySignature(v, r, s *big.Int) error
- type Account
- type AccountRepository
- type Block
- type BlockData
- type BlockDataDTO
- type BlockDataDTORepository
- type BlockDataRepository
- type BlockHeader
- func (bh *BlockHeader) GetLatestTokenID() *big.Int
- func (bh *BlockHeader) GetNonce() *big.Int
- func (bh *BlockHeader) GetNumber() *big.Int
- func (bh *BlockHeader) IsLatestTokenIDZero() bool
- func (bh *BlockHeader) IsNonceZero() bool
- func (bh *BlockHeader) IsNumberZero() bool
- func (bh *BlockHeader) SeLatestTokenID(n *big.Int)
- func (b *BlockHeader) Serialize() ([]byte, error)
- func (bh *BlockHeader) SetNonce(n *big.Int)
- func (bh *BlockHeader) SetNumber(n *big.Int)
- type BlockNumberByHash
- type BlockTransaction
- type BlockchainState
- func (bs *BlockchainState) GetLatestBlockNumber() *big.Int
- func (bs *BlockchainState) GetLatestTokenID() *big.Int
- func (bs *BlockchainState) IsLatestBlockNumberZero() bool
- func (bs *BlockchainState) IsLatestTokenIDZero() bool
- func (bs *BlockchainState) SeLatestTokenID(n *big.Int)
- func (b *BlockchainState) Serialize() ([]byte, error)
- func (bs *BlockchainState) SetLatestBlockNumber(n *big.Int)
- type BlockchainStateChangeEventDTORepository
- type BlockchainStateDTO
- type BlockchainStateDTORepository
- type BlockchainStateRepository
- type GenesisBlockData
- type GenesisBlockDataDTO
- type GenesisBlockDataDTORepository
- type GenesisBlockDataRepository
- type MempoolTransaction
- func (mtx MempoolTransaction) FromAddress() (string, error)
- func (mtx MempoolTransaction) FromPublicKey() (*ecdsa.PublicKey, error)
- func (mtx *MempoolTransaction) Serialize() ([]byte, error)
- func (bd *MempoolTransaction) ToDTO() *MempoolTransactionDTO
- func (mtx MempoolTransaction) Validate(chainID uint16, isPoA bool) error
- type MempoolTransactionDTO
- type MempoolTransactionDTORepository
- type MempoolTransactionRepository
- type NFTAsset
- type NFTAssetRepository
- type NonFungibleToken
- type NonFungibleTokenMetadata
- type NonFungibleTokenMetadataAttribute
- type NonFungibleTokenRepository
- type SignedTransaction
- func (stx SignedTransaction) FromAddress() (string, error)
- func (tx *SignedTransaction) GetBigIntFields() (*big.Int, *big.Int, *big.Int)
- func (stx *SignedTransaction) Serialize() ([]byte, error)
- func (tx *SignedTransaction) SetBigIntFields(v, r, s *big.Int)
- func (stx SignedTransaction) Validate(chainID uint16, isPoA bool) error
- type Token
- type TokenRepository
- type Transaction
- func (tx *Transaction) GetNonce() *big.Int
- func (tx *Transaction) GetTokenID() *big.Int
- func (tx *Transaction) GetTokenNonce() *big.Int
- func (tx Transaction) HashWithComicCoinStamp() ([]byte, error)
- func (tx *Transaction) IsNonceZero() bool
- func (tx *Transaction) IsTokenIDZero() bool
- func (tx *Transaction) IsTokenNonceZero() bool
- func (tx *Transaction) SetNonce(n *big.Int)
- func (tx *Transaction) SetTTokenID(n *big.Int)
- func (tx *Transaction) SetTokenNonce(n *big.Int)
- func (tx Transaction) Sign(privateKey *ecdsa.PrivateKey) (SignedTransaction, error)
- type Validator
- type Wallet
- type WalletRepository
Constants ¶
const ( NonFungibleTokenStateNotReady = "not_ready" NonFungibleTokenStateReady = "ready" )
const ( TransactionTypeCoin = "coin" TransactionTypeToken = "token" )
Variables ¶
var ErrChainForked = errors.New("blockchain forked, start resync")
ErrChainForked is returned from validateNextBlock if another node's chain is two or more blocks ahead of ours.
Functions ¶
func ToNonFungibleTokenIDsArray ¶
func ToNonFungibleTokenIDsArray(nftoks []*NonFungibleToken) []*big.Int
func ToTokenIDsArray ¶
func VerifySignature ¶
VerifySignature checks if the signature is valid by ensuring the V value is correct and that the signature follows the proper rules.
Types ¶
type Account ¶
type Account struct { // The unique identifier for this blockchain that we are managing the state for. ChainID uint16 `bson:"chain_id" json:"chain_id"` // The public address of the account. Address *common.Address `bson:"address" json:"address"` // The Nonce field in the Account struct is not directly related to the // Nonce field in the BlockHeader struct. Instead, it's used to prevent // replay attacks on transactions. // // In Ethereum and other blockchain systems, a nonce is a counter that is // used to prevent a transaction from being replayed on the network. When a // user wants to send a transaction, they need to specify the nonce value // for their account. The nonce value is incremented each time a transaction // is sent from the account. // // In this context, the Nonce field in the Account struct represents the // nonce value of the last transaction sent from the account. This value is // used to prevent replay attacks by ensuring that each transaction has a // unique nonce value. // // Here's how it works: // 1. When a user wants to send a transaction, they retrieve the current nonce value for their account from the blockchain. // 2. They increment the nonce value by 1 and include it in the transaction. // 3. The transaction is sent to the network and verified by the nodes. // 4. If the transaction is valid, the nonce value is incremented again and stored in the account's state. // // By including the Nonce field in the Account struct, the blockchain can // keep track of the nonce value for each account and prevent replay attacks. // // It's worth noting that the Nonce field in the BlockHeader struct has a // different purpose. It's used to solve the proof-of-work puzzle required // to mine a new block. NonceBytes []byte `bson:"nonce_bytes" json:"nonce_bytes"` // The balance of the account in coins. Balance uint64 `bson:"balance" json:"balance"` }
Account struct represents an entity in our blockchain whom has transfered between another account some amount of coins or non-fungible tokens.
When you create a wallet it will still not exist on the blockchain, only when you use this wallet to receive or send coins to another wallet will it become logged on the blockchain.
When an account exists on the blockchain, that means every node in the peer- -to-peer network will have this account record in their local storage. This is important because every-time a coin is mined, the miner takes a hash of the entire accounts database to verify the values in the account are consistent across all the peer-to-peer nodes in the distributed network; therefore, preventing fraud from occuring.
func NewAccountFromDeserialize ¶
NewAccountFromDeserialize deserializes an account from a byte slice. This method uses the cbor library to unmarshal the byte slice into an account.
func (*Account) IsNonceZero ¶
type AccountRepository ¶
type AccountRepository interface { // Upsert inserts or updates an account in the repository. Upsert(ctx context.Context, acc *Account) error // GetByAddress retrieves an account by its ID. GetByAddress(ctx context.Context, addr *common.Address) (*Account, error) // ListByChainID retrieves all accounts in the repository for the particular chain ID. ListByChainID(ctx context.Context, chainID uint16) ([]*Account, error) ListWithFilterByAddresses(ctx context.Context, addrs []*common.Address) ([]*Account, error) // DeleteByID deletes an account by its ID. DeleteByAddress(ctx context.Context, addr *common.Address) error // HashStateByChainID returns a hash based on the contents of the accounts and // their balances. This is added to each block and checked by peers. HashStateByChainID(ctx context.Context, chainID uint16) (string, error) OpenTransaction() error CommitTransaction() error DiscardTransaction() }
AccountRepository interface defines the methods for interacting with the account repository. This interface provides a way to manage accounts, including upserting, getting, listing, and deleting.
type Block ¶
type Block struct { // Header is the block header, which contains metadata about the block. Header *BlockHeader // The signature of this block's "Header" field which was applied by the // proof-of-authority validator. HeaderSignatureBytes []byte `bson:"header_signature_bytes" json:"header_signature_bytes"` // MerkleTree is the Merkle tree of transactions, which allows for efficient verification of transaction inclusion. MerkleTree *merkle.Tree[BlockTransaction] // The proof-of-authority validator whom executed the validation of // this block data in our blockchain. Validator *Validator `bson:"validator" json:"validator"` }
Block represents a group of transactions batched together. It contains a block header and a Merkle tree of transactions.
type BlockData ¶
type BlockData struct { // Hash is the unique hash of the block. Hash string `bson:"hash" json:"hash"` // Header is the block header, which contains metadata about the block. Header *BlockHeader `bson:"header" json:"header"` // The signature of this block's "Header" field which was applied by the // proof-of-authority validator. HeaderSignatureBytes []byte `bson:"header_signature_bytes" json:"header_signature_bytes"` // Trans is the list of (coin) transactions in the block. Trans []BlockTransaction `bson:"trans" json:"trans"` // The proof-of-authority validator whom executed the validation of // this block data in our blockchain. Validator *Validator `bson:"validator" json:"validator"` }
BlockData represents the data that can be serialized to disk and over the network. It contains the hash of the block, the block header, and the list of transactions in the block.
func BlockDataDTOToBlockData ¶
func BlockDataDTOToBlockData(bd *BlockDataDTO) *BlockData
func NewBlockData ¶
NewBlockData constructs block data from a block.
func NewBlockDataFromDeserialize ¶
NewBlockDataFromDeserialize deserializes a block data from a byte array. It returns the deserialized block data and an error if one occurs.
type BlockDataDTO ¶
type BlockDataDTO BlockData
BlockData represents the data that can be serialized to disk and over the network.
func BlockDataToBlockDataDTO ¶
func BlockDataToBlockDataDTO(bd *BlockData) *BlockDataDTO
BlockDataToBlockData method converts a `BlockData` data type into a `BlockDataDTO` data type.
func NewBlockDataDTOFromDeserialize ¶
func NewBlockDataDTOFromDeserialize(data []byte) (*BlockDataDTO, error)
NewBlockDataDTOFromDeserialize deserializes a block data from a byte array. It returns the deserialized block data and an error if one occurs.
func (*BlockDataDTO) Serialize ¶
func (b *BlockDataDTO) Serialize() ([]byte, error)
Serialize serializes a block data into a byte array. It returns the serialized byte array and an error if one occurs.
type BlockDataDTORepository ¶
type BlockDataDTORepository interface { GetFromBlockchainAuthorityByHash(ctx context.Context, hash string) (*BlockDataDTO, error) GetFromBlockchainAuthorityByHeaderNumber(ctx context.Context, headerNumber *big.Int) (*BlockDataDTO, error) }
BlockDataRepository is an interface that defines the methods for handling the Block Data via the network.
type BlockDataRepository ¶
type BlockDataRepository interface { // Upsert upserts a block data into the repository. // It takes a block data and returns an error if one occurs. Upsert(ctx context.Context, bd *BlockData) error // GetByHash gets a block data by its hash. // It takes a hash and returns the block data and an error if one occurs. GetByHash(ctx context.Context, hash string) (*BlockData, error) GetByHeaderNumber(ctx context.Context, headerNumber *big.Int) (*BlockData, error) GetByTransactionNonce(ctx context.Context, txNonce *big.Int) (*BlockData, error) // ListByChainID lists all block data in the repository for the particular chain. ListByChainID(ctx context.Context, chainID uint16) ([]*BlockData, error) // DeleteByHash deletes a block data by its hash. // It takes a hash and returns an error if one occurs. DeleteByHash(ctx context.Context, hash string) error // ListBlockTransactionsByAddress lists all the transactions for a particular address. ListBlockTransactionsByAddress(ctx context.Context, address *common.Address) ([]*BlockTransaction, error) // ListBlockTransactionsByAddress lists all the transactions for a particular address. ListWithLimitForBlockTransactionsByAddress(ctx context.Context, address *common.Address, limit int64) ([]*BlockTransaction, error) GetByBlockTransactionTimestamp(ctx context.Context, timestamp uint64) (*BlockData, error) // GetLatestBlockTransactionByAddress will return the most recent block transaction for the particular address. GetLatestBlockTransactionByAddress(ctx context.Context, address *common.Address) (*BlockTransaction, error) GetLatestTokenIDByChainID(ctx context.Context, chainID uint16) (*big.Int, error) ListOwnedTokenBlockTransactionsByAddress(ctx context.Context, address *common.Address) ([]*BlockTransaction, error) OpenTransaction() error CommitTransaction() error DiscardTransaction() }
BlockDataRepository is an interface that defines the methods for interacting with block data. It provides methods for upserting, getting, listing, and deleting block data.
type BlockHeader ¶
type BlockHeader struct { ChainID uint16 `bson:"chain_id" json:"chain_id"` // Keep track of which chain this block belongs to. NumberBytes []byte `bson:"number_bytes" json:"number_bytes"` // Ethereum: Block number in the chain. NumberString string `bson:"-" json:"number_string"` // Read-only response in string format - will not be saved in database, only returned via API. PrevBlockHash string `bson:"prev_block_hash" json:"prev_block_hash"` // Bitcoin: Hash of the previous block in the chain. TimeStamp uint64 `bson:"timestamp" json:"timestamp"` // Bitcoin: Time the block was mined. Difficulty uint16 `bson:"difficulty" json:"difficulty"` // Ethereum: Number of 0's needed to solve the hash solution. Beneficiary common.Address `bson:"beneficiary" json:"beneficiary"` // Ethereum: The account who is receiving fees . TransactionFee uint64 `bson:"transaction_fee" json:"transaction_fee"` // ComicCoin: Fee that must be paid for every transaction. This value is provided by the authority. // The StateRoot represents a hash of the in-memory account balance // database. This field allows the blockchain to provide a guarantee that // the accounting of the transactions and fees for each account on each // node is exactly the same. StateRoot string `bson:"state_root" json:"state_root"` // Ethereum: Represents a hash of the accounts and their balances. TransRoot string `bson:"trans_root" json:"trans_root"` // Both: Represents the merkle tree root hash for the transactions in this block. NonceBytes []byte `bson:"nonce_bytes" json:"nonce_bytes"` // Both: Value identified to solve the hash solution. NonceString string `bson:"-" json:"nonce_string"` // Read-only response in string format - will not be saved in database, only returned via API. LatestTokenIDBytes []byte `bson:"latest_token_id_bytes" json:"latest_token_id_bytes"` // ComicCoin: The latest token that the blockchain points to. LatestTokenIDString string `bson:"-" json:"latest_token_id_string"` // Read-only response in string format - will not be saved in database, only returned via API. TokensRoot string `bson:"tokens_root" json:"tokens_root"` // ComicCoin: Represents the hash of all the tokens and their owners. }
BlockHeader represents common information required for each block.
func (*BlockHeader) GetLatestTokenID ¶
func (bh *BlockHeader) GetLatestTokenID() *big.Int
func (*BlockHeader) GetNonce ¶
func (bh *BlockHeader) GetNonce() *big.Int
func (*BlockHeader) GetNumber ¶
func (bh *BlockHeader) GetNumber() *big.Int
func (*BlockHeader) IsLatestTokenIDZero ¶
func (bh *BlockHeader) IsLatestTokenIDZero() bool
func (*BlockHeader) IsNonceZero ¶
func (bh *BlockHeader) IsNonceZero() bool
func (*BlockHeader) IsNumberZero ¶
func (bh *BlockHeader) IsNumberZero() bool
func (*BlockHeader) SeLatestTokenID ¶
func (bh *BlockHeader) SeLatestTokenID(n *big.Int)
func (*BlockHeader) Serialize ¶
func (b *BlockHeader) Serialize() ([]byte, error)
Serialize serializes a block header into a byte array. It returns the serialized byte array and an error if one occurs.
func (*BlockHeader) SetNonce ¶
func (bh *BlockHeader) SetNonce(n *big.Int)
func (*BlockHeader) SetNumber ¶
func (bh *BlockHeader) SetNumber(n *big.Int)
type BlockNumberByHash ¶
type BlockTransaction ¶
type BlockTransaction struct { SignedTransaction TimeStamp uint64 `bson:"timestamp" json:"timestamp"` // Ethereum: The time the transaction was received. Fee uint64 `bson:"fee" json:"fee"` // ComicCoin: Fee paid for this transaction to the ComicCoin authority. }
BlockTransaction represents the transaction as it's recorded inside a block. This includes a timestamp and gas fees.
func NewBlockTransactionFromDeserialize ¶
func NewBlockTransactionFromDeserialize(data []byte) (*BlockTransaction, error)
func (BlockTransaction) Equals ¶
func (tx BlockTransaction) Equals(otherTx BlockTransaction) bool
Equals implements the merkle Hashable interface for providing an equality check between two block transactions. If the nonce and signatures are the same, the two blocks are the same.
func (BlockTransaction) Hash ¶
func (tx BlockTransaction) Hash() ([]byte, error)
Hash implements the merkle Hashable interface for providing a hash of a block transaction.
func (*BlockTransaction) Serialize ¶
func (dto *BlockTransaction) Serialize() ([]byte, error)
type BlockchainState ¶
type BlockchainState struct { // The unique identifier for this blockchain that we are managing the state for. ChainID uint16 `bson:"chain_id" json:"chain_id"` LatestBlockNumberBytes []byte `bson:"latest_block_number_bytes" json:"latest_block_number_bytes"` LatestHash string `bson:"latest_hash" json:"latest_hash"` LatestTokenIDBytes []byte `bson:"latest_token_id_bytes" json:"latest_token_id_bytes"` // The current transaction fee to be apply for every transaction as of this moment in time that is received by the Authority from the Global Blockchain Network. TransactionFee uint64 `bson:"transaction_fee" json:"transaction_fee"` AccountHashState string `bson:"account_hash_state" json:"account_hash_state"` TokenHashState string `bson:"token_hash_state" json:"token_hash_state"` }
BlockchainState represents the entire blockchain state at the current moment in time of operation.
func BlockchainStateDTOToBlockchainState ¶
func BlockchainStateDTOToBlockchainState(bd *BlockchainStateDTO) *BlockchainState
func NewBlockchainStateFromDeserialize ¶
func NewBlockchainStateFromDeserialize(data []byte) (*BlockchainState, error)
NewBlockchainStateFromDeserialize deserializes an blockchainState from a byte slice. This method uses the cbor library to unmarshal the byte slice into an blockchainState.
func (*BlockchainState) GetLatestBlockNumber ¶
func (bs *BlockchainState) GetLatestBlockNumber() *big.Int
func (*BlockchainState) GetLatestTokenID ¶
func (bs *BlockchainState) GetLatestTokenID() *big.Int
func (*BlockchainState) IsLatestBlockNumberZero ¶
func (bs *BlockchainState) IsLatestBlockNumberZero() bool
func (*BlockchainState) IsLatestTokenIDZero ¶
func (bs *BlockchainState) IsLatestTokenIDZero() bool
func (*BlockchainState) SeLatestTokenID ¶
func (bs *BlockchainState) SeLatestTokenID(n *big.Int)
func (*BlockchainState) Serialize ¶
func (b *BlockchainState) Serialize() ([]byte, error)
Serialize serializes the blockchain state into a byte slice. This method uses the cbor library to marshal the blockchainState into a byte slice.
func (*BlockchainState) SetLatestBlockNumber ¶
func (bs *BlockchainState) SetLatestBlockNumber(n *big.Int)
type BlockchainStateChangeEventDTORepository ¶
type BlockchainStateChangeEventDTORepository interface {
SubscribeToBlockchainAuthority(ctx context.Context, chainID uint16) (<-chan uint16, error)
}
BlockchainStateChangeEventRepository is an interface that defines the methods for handling the blockchain state via the network using server sent events (SSE).
type BlockchainStateDTO ¶
type BlockchainStateDTO BlockchainState
BlockchainState represents the data that can be serialized to disk and over the network.
func BlockchainStateToBlockchainStateDTO ¶
func BlockchainStateToBlockchainStateDTO(bd *BlockchainState) *BlockchainStateDTO
BlockDataToBlockchainState method converts a `BlockchainState` data type into a `BlockchainStateDTO` data type.
func NewBlockchainStateDTOFromDeserialize ¶
func NewBlockchainStateDTOFromDeserialize(data []byte) (*BlockchainStateDTO, error)
NewBlockchainStateDTOFromDeserialize deserializes struct data from a byte array. It returns the deserialized struct data and an error if one occurs.
func (*BlockchainStateDTO) Serialize ¶
func (b *BlockchainStateDTO) Serialize() ([]byte, error)
Serialize serializes golang struct data into a byte array. It returns the serialized byte array and an error if one occurs.
type BlockchainStateDTORepository ¶
type BlockchainStateDTORepository interface {
GetFromBlockchainAuthorityByChainID(ctx context.Context, chainID uint16) (*BlockchainStateDTO, error)
}
BlockchainStateRepository is an interface that defines the methods for handling the blockchain state via the network.
type BlockchainStateRepository ¶
type BlockchainStateRepository interface { // Upsert inserts or updates an blockchain state in the repository. UpsertByChainID(ctx context.Context, acc *BlockchainState) error // GetByChainID retrieves an blockchain state by its chain ID. GetByChainID(ctx context.Context, chainID uint16) (*BlockchainState, error) // ListAll retrieves all blockchain states in the repository. ListAll(ctx context.Context) ([]*BlockchainState, error) // DeleteByChainID deletes an blockchain state by its chain ID. DeleteByChainID(ctx context.Context, chainID uint16) error GetUpdateChangeStreamChannel(ctx context.Context) (<-chan BlockchainState, chan struct{}, error) OpenTransaction() error CommitTransaction() error DiscardTransaction() }
type GenesisBlockData ¶
type GenesisBlockData BlockData
GenesisBlockData represents the first block (data) in our blockchain.
func BlockDataToGenesisBlockData ¶
func BlockDataToGenesisBlockData(bd *BlockData) *GenesisBlockData
BlockDataToGenesisBlockData method converts a `BlockData` data type into a `GenesisBlockData` data type.
func GenesisBlockDataDTOToGenesisBlockData ¶
func GenesisBlockDataDTOToGenesisBlockData(bd *GenesisBlockDataDTO) *GenesisBlockData
func NewGenesisBlockDataFromDeserialize ¶
func NewGenesisBlockDataFromDeserialize(data []byte) (*GenesisBlockData, error)
NewGenesisBlockDataFromDeserialize deserializes a genesis block data from a byte array. It returns the deserialized block data and an error if one occurs.
func (*GenesisBlockData) Serialize ¶
func (b *GenesisBlockData) Serialize() ([]byte, error)
Serialize serializes a genesis block data into a byte array. It returns the serialized byte array and an error if one occurs.
type GenesisBlockDataDTO ¶
type GenesisBlockDataDTO GenesisBlockData
GenesisBlockData represents the data that can be serialized to disk and over the network.
func GenesisBlockDataToGenesisBlockDataDTO ¶
func GenesisBlockDataToGenesisBlockDataDTO(bd *GenesisBlockData) *GenesisBlockDataDTO
BlockDataToGenesisBlockData method converts a `GenesisBlockData` data type into a `GenesisBlockDataDTO` data type.
func NewGenesisBlockDataDTOFromDeserialize ¶
func NewGenesisBlockDataDTOFromDeserialize(data []byte) (*GenesisBlockDataDTO, error)
NewGenesisBlockDataDTOFromDeserialize deserializes a genesis block data from a byte array. It returns the deserialized block data and an error if one occurs.
func (*GenesisBlockDataDTO) Serialize ¶
func (b *GenesisBlockDataDTO) Serialize() ([]byte, error)
Serialize serializes a genesis block data into a byte array. It returns the serialized byte array and an error if one occurs.
type GenesisBlockDataDTORepository ¶
type GenesisBlockDataDTORepository interface {
GetFromBlockchainAuthorityByChainID(ctx context.Context, chainID uint16) (*GenesisBlockDataDTO, error)
}
GenesisBlockDataRepository is an interface that defines the methods for handling the Genesis Block Data via the network.
type GenesisBlockDataRepository ¶
type GenesisBlockDataRepository interface { GetByChainID(ctx context.Context, chainID uint16) (*GenesisBlockData, error) UpsertByChainID(ctx context.Context, genesis *GenesisBlockData) error OpenTransaction() error CommitTransaction() error DiscardTransaction() }
GenesisBlockDataRepository is an interface that defines the methods for handling the Genesis Block Data in our local database.
type MempoolTransaction ¶
type MempoolTransaction struct { ID primitive.ObjectID `bson:"_id" json:"id"` // The signed transaction data, including sender, recipient, amount, and other metadata like V, R, S, etc. SignedTransaction }
MempoolTransaction represents a transaction that is stored in the mempool. It contains the transaction data, as well as the ECDSA signature and recovery identifier.
func NewMempoolTransactionFromDeserialize ¶
func NewMempoolTransactionFromDeserialize(data []byte) (*MempoolTransaction, error)
NewMempoolTransactionFromDeserialize deserializes a mempool transaction from a byte slice. This method uses the cbor library to unmarshal the byte slice into a transaction.
func (MempoolTransaction) FromAddress ¶
func (mtx MempoolTransaction) FromAddress() (string, error)
FromAddress extracts the account address from the signed transaction by recovering the public key from the signature.
func (MempoolTransaction) FromPublicKey ¶
func (mtx MempoolTransaction) FromPublicKey() (*ecdsa.PublicKey, error)
func (*MempoolTransaction) Serialize ¶
func (mtx *MempoolTransaction) Serialize() ([]byte, error)
Serialize serializes the mempool transaction into a byte slice. This method uses the cbor library to marshal the transaction into a byte slice.
func (*MempoolTransaction) ToDTO ¶
func (bd *MempoolTransaction) ToDTO() *MempoolTransactionDTO
ToDTO method converts a `MempoolTransaction` data type into a `MempoolTransactionDTO` data type.
type MempoolTransactionDTO ¶
type MempoolTransactionDTO MempoolTransaction
MempoolTransaction represents the data that can be serialized to disk and over the network.
func NewMempoolTransactionDTOFromDeserialize ¶
func NewMempoolTransactionDTOFromDeserialize(data []byte) (*MempoolTransactionDTO, error)
NewMempoolTransactionDTOFromDeserialize deserializes struct data from a byte array. It returns the deserialized struct data and an error if one occurs.
func (*MempoolTransactionDTO) Serialize ¶
func (b *MempoolTransactionDTO) Serialize() ([]byte, error)
Serialize serializes golang struct data into a byte array. It returns the serialized byte array and an error if one occurs.
func (*MempoolTransactionDTO) ToIDO ¶
func (bd *MempoolTransactionDTO) ToIDO() *MempoolTransaction
type MempoolTransactionDTORepository ¶
type MempoolTransactionDTORepository interface {
SubmitToBlockchainAuthority(ctx context.Context, dto *MempoolTransactionDTO) error
}
MempoolTransactionRepository is an interface that defines the methods for handling the blockchain state via the network.
type MempoolTransactionRepository ¶
type MempoolTransactionRepository interface { GetByID(ctx context.Context, id primitive.ObjectID) (*MempoolTransaction, error) // Upsert inserts or updates a mempool transaction in the repository. Upsert(ctx context.Context, mempoolTx *MempoolTransaction) error // ListAll retrieves all mempool transactions in the repository. ListByChainID(ctx context.Context, chainID uint16) ([]*MempoolTransaction, error) // DeleteByChainID deletes all mempool transactions in the repository for the particular chainID. DeleteByChainID(ctx context.Context, chainID uint16) error DeleteByID(ctx context.Context, id primitive.ObjectID) error GetInsertionChangeStreamChannel(ctx context.Context) (<-chan MempoolTransaction, chan struct{}, error) }
MempoolTransactionRepository interface defines the methods for interacting with the mempool transaction repository. This interface provides a way to manage mempool transactions, including upserting, listing, and deleting.
type NFTAsset ¶
type NFTAsset struct { Filename string `json:"filename"` // The name of the file being retrieved, derived from Content-Disposition headers. Content []byte `json:"content"` // The raw file content in bytes. ContentType string `json:"content_type"` // The MIME type of the file, determined by server response headers. ContentLength uint64 `json:"content_length"` // The length of the content in bytes. }
NFTAsset represents a digital asset.
type NFTAssetRepository ¶
type NFTAssetRepository interface { // Version fetches the current version of the remote IPFS server. // It returns the version as a string and any error encountered. Version(ctx context.Context) (string, error) // PinAddViaFilepath pins a file located at the specified filepath to the IPFS server. // The filepath should be a full local path, and it returns the CID of the pinned file or an error. PinAddViaFilepath(ctx context.Context, filepath string) (string, error) // Get retrieves a file from the IPFS server using its CID (Content Identifier). // It returns a NFTAsset containing file metadata, content, and any error encountered. Get(ctx context.Context, cidString string) (*NFTAsset, error) }
NFTAssetRepository defines an interface for interacting with a remote IPFS server custom built to exclusively host NFT assets for the ComicCoin blockchain network. This interface abstracts common IPFS operations, including retrieving the IPFS server version, pinning a file by its filepath, and fetching a file by CID.
type NonFungibleToken ¶
type NonFungibleToken struct { TokenID *big.Int `json:"token_id"` MetadataURI string `json:"metadata_uri"` Metadata *NonFungibleTokenMetadata `json:"metadata"` State string `bson:"state" json:"state"` }
func NewNonFungibleTokenFromDeserialize ¶
func NewNonFungibleTokenFromDeserialize(data []byte) (*NonFungibleToken, error)
NewNonFungibleTokenFromDeserialize deserializes an wallet from a byte slice. This method uses the cbor library to unmarshal the byte slice into an wallet.
func (*NonFungibleToken) Serialize ¶
func (b *NonFungibleToken) Serialize() ([]byte, error)
Serialize serializes the wallet into a byte slice. This method uses the cbor library to marshal the wallet into a byte slice.
type NonFungibleTokenMetadata ¶
type NonFungibleTokenMetadata struct { Image string `bson:"image" json:"image"` ExternalURL string `bson:"external_url" json:"external_url"` Description string `bson:"description" json:"description"` Name string `bson:"name" json:"name"` Attributes []*NonFungibleTokenMetadataAttribute `bson:"attributes" json:"attributes"` BackgroundColor string `bson:"background_color" json:"background_color"` AnimationURL string `bson:"animation_url" json:"animation_url"` YoutubeURL string `bson:"youtube_url" json:"youtube_url"` }
type NonFungibleTokenRepository ¶
type NonFungibleTokenRepository interface { // Upsert inserts or updates an nfts in the repository. Upsert(acc *NonFungibleToken) error // GetByID retrieves an nft by its token id. GetByTokenID(tokenID *big.Int) (*NonFungibleToken, error) // ListAll retrieves all nfts in the repository. ListAll() ([]*NonFungibleToken, error) // ListByTokenIDs retrieves nfts that have the token is in the parameter ListWithFilterByTokenIDs(tokIDs []*big.Int) ([]*NonFungibleToken, error) // DeleteByID deletes an nft by its token id. DeleteByTokenID(tokenID *big.Int) error OpenTransaction() error CommitTransaction() error DiscardTransaction() }
type SignedTransaction ¶
type SignedTransaction struct { Transaction VBytes []byte `bson:"v_bytes,omitempty" json:"v_bytes"` // Ethereum: Recovery identifier, either 29 or 30 with comicCoinID. RBytes []byte `bson:"r_bytes,omitempty" json:"r_bytes"` // Ethereum: First coordinate of the ECDSA signature. SBytes []byte `bson:"s_bytes,omitempty" json:"s_bytes"` // Ethereum: Second coordinate of the ECDSA signature. }
SignedTransaction is a signed version of the transaction. This is how clients like a wallet provide transactions for inclusion into the blockchain.
func NewSignedTransactionFromDeserialize ¶
func NewSignedTransactionFromDeserialize(data []byte) (*SignedTransaction, error)
func (SignedTransaction) FromAddress ¶
func (stx SignedTransaction) FromAddress() (string, error)
FromAddress extracts the account address from the signed transaction by recovering the public key from the signature.
func (*SignedTransaction) GetBigIntFields ¶
GetBigIntFields retrieves *big.Int values from []byte fields after loading from MongoDB.
func (*SignedTransaction) Serialize ¶
func (stx *SignedTransaction) Serialize() ([]byte, error)
func (*SignedTransaction) SetBigIntFields ¶
func (tx *SignedTransaction) SetBigIntFields(v, r, s *big.Int)
SetBigIntFields allows setting *big.Int values to []byte fields for MongoDB storage.
func (SignedTransaction) Validate ¶
func (stx SignedTransaction) Validate(chainID uint16, isPoA bool) error
Validate checks if the transaction is valid. It verifies the signature, makes sure the account addresses are correct, and checks if the 'from' and 'to' accounts are not the same (unless you are the proof of authority!)
type Token ¶
type Token struct { // The unique identifier for this blockchain that we are managing the state for. ChainID uint16 `bson:"chain_id" json:"chain_id"` IDBytes []byte `bson:"id_bytes" json:"id_bytes"` Owner *common.Address `bson:"owner" json:"owner"` MetadataURI string `bson:"metadata_uri" json:"metadata_uri"` // ComicCoin: URI pointing to Token metadata file (if this transaciton is an Token). NonceBytes []byte `bson:"nonce_bytes" json:"nonce_bytes"` // ComicCoin: Newly minted tokens always start at zero and for every transaction action afterwords (transfer, burn, etc) this value is increment by 1. }
func NewTokenFromDeserialize ¶
NewTokenFromDeserialize deserializes an token from a byte slice. This method uses the cbor library to unmarshal the byte slice into an token.
func (*Token) IsLatestTokenIDZero ¶
func (*Token) IsNonceZero ¶
func (*Token) SeLatestTokenID ¶
type TokenRepository ¶
type TokenRepository interface { // Upsert inserts or updates an token in the repository. Upsert(ctx context.Context, tok *Token) error // GetByAddress retrieves an token by its ID. GetByID(ctx context.Context, id *big.Int) (*Token, error) // ListByChainID retrieves all accounts in the repository for the particular chain ID. ListByChainID(ctx context.Context, chainID uint16) ([]*Token, error) // ListByOwner retrieves all the tokens in the repository that belongs // to the owner address. ListByOwner(ctx context.Context, owner *common.Address) ([]*Token, error) // CountByOwner counts all the tokens owned by the owner. CountByOwner(ctx context.Context, owner *common.Address) (int64, error) // DeleteByID deletes an token by its ID. DeleteByID(ctx context.Context, id *big.Int) error // HashStateByChainID returns a hash based on the contents of the tokens and // their metadata. This is added to each block and checked by peers. HashStateByChainID(ctx context.Context, chainID uint16) (string, error) OpenTransaction() error CommitTransaction() error DiscardTransaction() }
TokenRepository interface defines the methods for interacting with the token repository. This interface provides a way to manage tokens, including upserting, getting, listing, and deleting.
type Transaction ¶
type Transaction struct { ChainID uint16 `bson:"chain_id" json:"chain_id"` // Ethereum: The chain id that is listed in the genesis file. NonceBytes []byte `bson:"nonce_bytes" json:"nonce_bytes"` // Ethereum: Unique id for the transaction supplied by the user. NonceString string `bson:"-" json:"nonce_string"` // Read-only response in string format - will not be saved in database, only returned via API. From *common.Address `bson:"from" json:"from"` // Ethereum: Account sending the transaction. Will be checked against signature. To *common.Address `bson:"to" json:"to"` // Ethereum: Account receiving the benefit of the transaction. Value uint64 `bson:"value" json:"value"` // Ethereum: Monetary value received from this transaction. Data []byte `bson:"data" json:"data"` // Ethereum: Extra data related to the transaction. DataString string `bson:"-" json:"data_string"` // Read-only response in string format - will not be saved in database, only returned via API. Type string `bson:"type" json:"type"` // ComicCoin: The type of transaction this is, either `coin` or `token`. TokenIDBytes []byte `bson:"token_id_bytes" json:"token_id_bytes"` // ComicCoin: Unique identifier for the Token (if this transaciton is an Token). TokenIDString string `bson:"-" json:"token_id_string"` // Read-only response in string format - will not be saved in database, only returned via API. TokenMetadataURI string `bson:"token_metadata_uri" json:"token_metadata_uri"` // ComicCoin: URI pointing to Token metadata file (if this transaciton is an Token). TokenNonceBytes []byte `bson:"token_nonce_bytes" json:"token_nonce_bytes"` // ComicCoin: For every transaction action (mint, transfer, burn, etc), increment token nonce by value of 1. TokenNonceString string `bson:"-" json:"token_nonce_string"` // Read-only response in string format - will not be saved in database, only returned via API. }
Transaction structure represents a transfer of coins between accounts which have not been added to the blockchain yet and are waiting for the miner to receive and verify. Once transactions have been veriried they will be deleted from our system as they will live in the blockchain afterwords.
func (*Transaction) GetNonce ¶
func (tx *Transaction) GetNonce() *big.Int
func (*Transaction) GetTokenID ¶
func (tx *Transaction) GetTokenID() *big.Int
func (*Transaction) GetTokenNonce ¶
func (tx *Transaction) GetTokenNonce() *big.Int
func (Transaction) HashWithComicCoinStamp ¶
func (tx Transaction) HashWithComicCoinStamp() ([]byte, error)
HashWithComicCoinStamp creates a unique hash of the transaction and prepares it for signing by adding a special "stamp".
func (*Transaction) IsNonceZero ¶
func (tx *Transaction) IsNonceZero() bool
func (*Transaction) IsTokenIDZero ¶
func (tx *Transaction) IsTokenIDZero() bool
func (*Transaction) IsTokenNonceZero ¶
func (tx *Transaction) IsTokenNonceZero() bool
func (*Transaction) SetNonce ¶
func (tx *Transaction) SetNonce(n *big.Int)
func (*Transaction) SetTTokenID ¶
func (tx *Transaction) SetTTokenID(n *big.Int)
func (*Transaction) SetTokenNonce ¶
func (tx *Transaction) SetTokenNonce(n *big.Int)
func (Transaction) Sign ¶
func (tx Transaction) Sign(privateKey *ecdsa.PrivateKey) (SignedTransaction, error)
Sign function signs the transaction using the user's private key and returns a signed version of that transaction.
type Validator ¶
type Validator struct { ID string `bson:"id" json:"id"` PublicKeyBytes []byte `bson:"public_key_bytes" json:"public_key_bytes"` }
Validator represents a trusted validator in the network.
func (*Validator) GetPublicKeyECDSA ¶
type Wallet ¶
type Wallet struct { // The (Optional) description for this wallet. Label string `bson:"label" json:"label"` // The public address of the wallet. Address *common.Address `bson:"address" json:"address"` // FileContent contains KeystoreBytes []byte `bson:"keystore_bytes" json:"keystore_bytes"` }
func NewWalletFromDeserialize ¶
NewWalletFromDeserialize deserializes an wallet from a byte slice. This method uses the cbor library to unmarshal the byte slice into an wallet.
type WalletRepository ¶
type WalletRepository interface { // Upsert inserts or updates an wallet in the repository. Upsert(ctx context.Context, acc *Wallet) error // GetByID retrieves an wallet by its Address. GetByAddress(ctx context.Context, address *common.Address) (*Wallet, error) // ListAll retrieves all wallets in the repository. ListAll(ctx context.Context) ([]*Wallet, error) // ListAllAddresses retrieves all wallet addresses in the repository. ListAllAddresses(ctx context.Context) ([]*common.Address, error) // DeleteByID deletes an wallet by its Address. DeleteByAddress(ctx context.Context, address *common.Address) error OpenTransaction() error CommitTransaction() error DiscardTransaction() }