Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions contracts/CreditStation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ contract CreditStation is AccessManaged, Pausable, IVersioned, ICreditStation {
return _paymentsByUser.length(user);
}

/// @notice Gets the last paymentId made in the system
/// @return paymentId returns the last payment ID made in the system
function getLastPaymentId() external view override returns (PaymentId paymentId) {
return _previous(_nextPaymentId);
}

/// @notice Gets the last payment made by a user
/// @param user The address of the buyer
/// @return paymentId returns the last payment ID if there is one, reverts otherwise
Expand Down Expand Up @@ -280,4 +286,11 @@ contract CreditStation is AccessManaged, Pausable, IVersioned, ICreditStation {
function _next(PaymentId id) private pure returns (PaymentId next) {
return PaymentId.wrap(PaymentId.unwrap(id) + 1);
}

/// @notice Get payment ID previous before the provided one
/// @param id The payment ID
/// @return previous The previous payment ID
function _previous(PaymentId id) private pure returns (PaymentId previous) {
return PaymentId.wrap(PaymentId.unwrap(id) - 1);
}
}
3 changes: 3 additions & 0 deletions contracts/interfaces/ICreditStation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ interface ICreditStation {
function getLastPayment(
address user
) external view returns (PaymentId paymentId);
/// @notice Gets the last paymentId made in the system
/// @return paymentId returns the last payment ID made in the system
function getLastPaymentId() external view returns (PaymentId paymentId);
/// @notice Gets the payment IDs made by a user within a specific range (MAX 10_000 each query)
/// @param user The address of the buyer
/// @param startIndex The start index (inclusive) of the payments to get
Expand Down
2 changes: 2 additions & 0 deletions test/CreditStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ describe("CreditStation", () => {
creditStation,
"InvalidIndices"
);

await creditStation.getLastPaymentId().should.eventually.be.equal(2n);
});

it("should revert when getting non-existing payment info", async () => {
Expand Down