Experimental Solidity FP contract abstraction
const merge = require('lodash.merge')
const mapObject = require('lodash.map')
const out = value => ({ type: 'RETURN', value })
const update = state => ({ type: 'UPDATE', state })
const mapEffect = effects => {
}
class Bank {
owner = 0x0,
balances = {},
constructor(state, { sender }) {
return merge(state, {
owner: sender
})
},
deposit(state, { sender, value }) {
return merge(state, {
balances: mapObject(state.balances, (balance, address) => {
return address === sender
? balance + value
: balance
})
})
},
withdraw(state, msg: { sender, value, send }, args: { value }) {
return merge(state, {
balances: mapObject(state.balances, (balance, address) => {
return address === sender ?
balance >= value : balance - value
: new Error('Insufficient funds')
: balance
}
})
}
}
export default Bank