Transactions

Git Source

Author: Tinotenda Joe

This contract serves as a ledger for recording transactions within a supply chain. /// Logic here keeps track of custody : Owner1 -> Owner2 -> Owner3 -> Owner4 -> Owner5 -> ...

State Variables

Owner

This holds as the first initiator of a specific transaction / exchange in the supply chain. eg creator or supplier of the raw materials, later own can be traced back.But this is not limited to only a single owner, decentralized nature of this transaction ledger will enable any participant to hold the position as an 'Owner' that is any current entity in custody of the comodities

address public Owner;

transactionCount

uint256 public transactionCount;

txns

mapping(uint256 => transactions) public txns;

Functions

constructor

constructor(address _ownerAddress);

createTransactionEntry

Increases the total transaction count and emits an event at the end. Validates previous transaction for all transactions other than the first one.

Establishes a new transaction entry in the ledger

function createTransactionEntry(
    bytes32 _transactionHash,
    address _from,
    address _to,
    bytes32 _prevTransaction,
    string memory _latitude,
    string memory _longitude
) public;

Parameters

NameTypeDescription
_transactionHashbytes32Id of the transaction
_fromaddressSource address of the transaction
_toaddressDestination address for the transaction
_prevTransactionbytes32Hash of the previous transaction to maintain continuity
_latitudestringLatitude of the transaction
_longitudestringLongitude of the transaction

getAllTransactions

Fetch all the transaction entries recorded in the ledger

function getAllTransactions() public view returns (transactions[] memory);

Returns

NameTypeDescription
<none>transactions[]Array containing all the transactions in the ledger

getAllTransactionsCount

Retrieves the total count of transactions in the ledger

function getAllTransactionsCount() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256Total count of transactions

getTransaction

Fetches the details of a specific transaction by its index

function getTransaction(uint256 id)
    public
    view
    returns (bytes32, address, address, bytes32, string memory, string memory, uint256);

Parameters

NameTypeDescription
iduint256Index of the transaction to fetch

Returns

NameTypeDescription
<none>bytes32Transaction details: hash, source address, destination address, previous transaction, latitude, longitude, timestamp
<none>address
<none>address
<none>bytes32
<none>string
<none>string
<none>uint256

Events

transactionCreated

Event emitted once a transaction gets created successfully

event transactionCreated(
    bytes32 _transactionHash, address _from, address _to, bytes32 _prevTransaction, string _latitude, string _longitude
);

Errors

TRANSACTION_ERROR_OCCURRED

tracks erros. thrown from createTransactionEntry fx when there is a transaction related error during entry creation

error TRANSACTION_ERROR_OCCURRED();

Structs

transactions

Represents a transaction in the ledger with respective details

struct transactions {
    bytes32 transactionHash;
    address fromAddr;
    address toAddr;
    bytes32 prevTransaction;
    string latitude;
    string longitude;
    uint256 timestamp;
}