Skip to content

Module dev_simple_pay.erl

A simple device that allows the operator to specify a price for a request and then charge the user for it, on a per message basis.

Description

The device's ledger is stored in the node message at simple_pay_ledger, and can be topped-up by either the operator, or an external device. The price is specified in the node message at simple_pay_price. This device acts as both a pricing device and a ledger device, by p4's definition.

Function Index

balance/3Get the balance of a user in the ledger.
charge/3Preprocess a request by checking the ledger and charging the user.
estimate/3Estimate the cost of a request by counting the number of messages in the request, then multiplying by the per-message price.
get_balance/2*Get the balance of a user in the ledger.
get_balance_and_top_up_test/0*
is_operator/2*Check if the request is from the operator.
is_operator/3*
set_balance/3*Adjust a user's balance, normalizing their wallet ID first.
test_opts/1*
topup/3Top up the user's balance in the ledger.

Function Details

balance/3

balance(X1, RawReq, NodeMsg) -> any()

Get the balance of a user in the ledger.

charge/3

charge(X1, RawReq, NodeMsg) -> any()

Preprocess a request by checking the ledger and charging the user. We can charge the user at this stage because we know statically what the price will be

estimate/3

estimate(X1, EstimateReq, NodeMsg) -> any()

Estimate the cost of a request by counting the number of messages in the request, then multiplying by the per-message price. The operator does not pay for their own requests.

get_balance/2 *

get_balance(Signer, NodeMsg) -> any()

Get the balance of a user in the ledger.

get_balance_and_top_up_test/0 *

get_balance_and_top_up_test() -> any()

is_operator/2 *

is_operator(Req, NodeMsg) -> any()

Check if the request is from the operator.

is_operator/3 *

is_operator(Req, NodeMsg, OperatorAddr) -> any()

set_balance/3 *

set_balance(Signer, Amount, NodeMsg) -> any()

Adjust a user's balance, normalizing their wallet ID first.

test_opts/1 *

test_opts(Ledger) -> any()

topup/3

topup(X1, Req, NodeMsg) -> any()

Top up the user's balance in the ledger.