Skip to content

Instantly share code, notes, and snippets.

@zsfelfoldi
Created December 9, 2019 10:08
Show Gist options
  • Save zsfelfoldi/b4da6b5ca7fa67d4ce919c413094bdc7 to your computer and use it in GitHub Desktop.
Save zsfelfoldi/b4da6b5ca7fa67d4ce919c413094bdc7 to your computer and use it in GitHub Desktop.
  • createDeposit(amount map[common.Address]uint64) depositID
    • sends a transaction to create a new deposit with the given target allowances
  • subscribeDepositEvents(ch chan struct {id depositID, state int})
    • sends an event to the given channel every time a deposit goes into pending, active or expired state
  • estimatedExpiry(id depositID) time.Duration
    • returns the estimated remaining time while cheques can still be written using this deposit
  • allowancesLeft(id depositID) map[common.Address]uint64
  • lastCheque(id depositID, to common.Address) (totalSpent, allowanceLeft uint64)
  • writeCheque(id depositID, to common.Address, amount uint64) (totalSpent, allowanceLeft uint64, proofOfPayment []byte)
    • creates a cheque if the deposit is in active state and there is enough allowance left (otherwise proofOfPayment should be nil)
    • allowances are nominated in currency units, the payment channel module converts it to probability based on the total deposit amount
    • proofOfPayment is a serialized format of the cheque. It should contain the following info:
      • address of the deposit contract
      • deposit ID
      • highest winning random number (incremental)
      • Merkle proof of the server being assigned to a random number range that contains the current highest winning number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment