# State

The ecocredit module uses the Cosmos SDK's KVStore directly for credit batch balances and supplies and the orm package (an abstraction over the KVStore) for table storage of credit type sequences, credit classes, and credit batches.

# Tradable Balance

TradableBalance is the tradable balance of a credit batch.

TradableBalance is stored directly in the KVStore:

0x0 | byte(address length) | []byte(address) | []byte(denom) --> []byte(amount)

# Tradable Supply

TradableSupply is the tradable supply of a credit batch.

TradableSupply is stored directly in the KVStore:

0x1 | []byte(denom) --> []byte(amount)

# Retired Balance

RetiredBalance is the retired balance of a credit batch.

RetiredBalance is stored directly in the KVStore:

0x2 | byte(address length) | []byte(address) | []byte(denom) --> []byte(amount)

# Retired Supply

RetiredSupply is the retired supply of a credit batch.

RetiredSupply is stored directly in the KVStore:

0x3 | []byte(denom) --> []byte(amount)

# Credit Type Sequence Table

CreditTypeSeq associates a sequence number with a credit type abbreviation.

The sequence number is incremented on a per credit type basis, and it exists for the purpose of providing a sequence number for the credit class ID. A credit class ID is the combination of a credit type abbreviation and a sequence number (e.g. C01 is the ID for the first "carbon" credit class).

The creditTypeSeqTable stores CreditTypeSeq:

0x4 | []byte(Abbreviation) -> ProtocolBuffer(CreditTypeSeq)

// CreditTypeSeq associates a sequence number with a credit type abbreviation.
// This represents the number of credit classes created with that credit type.
message CreditTypeSeq {
  // The credit type abbreviation
  string abbreviation = 1;

  // The sequence number of classes of the credit type
  uint64 seq_number = 2;
}

# Class Info Table

The classInfoTable stores ClassInfo:

0x5 | []byte(ClassId) -> ProtocolBuffer(ClassInfo)

// ClassInfo represents the high-level on-chain information for a credit class.
message ClassInfo {

  // class_id is the unique ID of credit class.
  string class_id = 1;

  // admin is the admin of the credit class.
  string admin = 2;

  // issuers are the approved issuers of the credit class.
  repeated string issuers = 3;

  // metadata is any arbitrary metadata to attached to the credit class.
  bytes metadata = 4;

  // credit_type describes the type of credit (e.g. carbon, biodiversity), as well as unit and precision.
  CreditType credit_type = 5;

  // The number of batches issued in this credit class.
  uint64 num_batches = 6;
}

# Batch Info Table

The batchInfoTable stores BatchInfo:

0x6 | []byte(BatchId) -> ProtocolBuffer(BatchInfo)

// BatchInfo represents the high-level on-chain information for a credit batch.
message BatchInfo {

  // class_id is the unique ID of credit class.
  string class_id = 1;

  // batch_denom is the unique ID of credit batch.
  string batch_denom = 2;

  // issuer is the issuer of the credit batch.
  string issuer = 3;

  // total_amount is the total number of active credits in the credit batch.
  // Some of the issued credits may be cancelled and will be removed from
  // total_amount and tracked in amount_cancelled. total_amount and
  // amount_cancelled will always sum to the original amount of credits that
  // were issued.
  string total_amount = 4;

  // metadata is any arbitrary metadata attached to the credit batch.
  bytes metadata = 5;

  // amount_cancelled is the number of credits in the batch that have been
  // cancelled, effectively undoing there issuance. The sum of total_amount and
  // amount_cancelled will always sum to the original amount of credits that
  // were issued.
  string amount_cancelled = 6;

  // start_date is the beginning of the period during which this credit batch
  // was quantified and verified.
  google.protobuf.Timestamp start_date = 7 [ (gogoproto.stdtime) = true ];

  // end_date is the end of the period during which this credit batch was
  // quantified and verified.
  google.protobuf.Timestamp end_date = 8 [ (gogoproto.stdtime) = true ];

  // project_location is the location of the project backing the credits in this
  // batch. Full documentation can be found in MsgCreateBatch.project_location.
  string project_location = 9;
}