mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-12 07:34:08 +00:00
2fb39ca4a3
* use PeerInfo in event handlers * use CidV1 and raw multicodec as default * add block stream abstraction * raises defect * adding dataset abstraction * move blockstream into own dir * reorg files and fix tests * rename dataset to blockset * wip * wip * adding basic test for treehash algo * run blockset tests along with with the rest * remove obsolete contents * fix chunker tests * rename bitswap and move to stores * rename bitwsap to blockexc and move to stores * moare project structure reorg
41 lines
1.2 KiB
Nim
41 lines
1.2 KiB
Nim
import std/math
|
|
import pkg/nitro
|
|
import pkg/questionable/results
|
|
import ../peercontext
|
|
|
|
export nitro
|
|
export results
|
|
export peercontext
|
|
|
|
push: {.upraises: [].}
|
|
|
|
const ChainId* = 0.u256 # invalid chain id for now
|
|
const Asset* = EthAddress.zero # invalid ERC20 asset address for now
|
|
const AmountPerChannel = (10'u64^18).u256 # 1 asset, ERC20 default is 18 decimals
|
|
|
|
func openLedgerChannel*(wallet: WalletRef,
|
|
hub: EthAddress,
|
|
asset: EthAddress): ?!ChannelId =
|
|
wallet.openLedgerChannel(hub, ChainId, asset, AmountPerChannel)
|
|
|
|
func getOrOpenChannel(wallet: WalletRef, peer: BlockExcPeerCtx): ?!ChannelId =
|
|
if channel =? peer.paymentChannel:
|
|
success channel
|
|
elif account =? peer.account:
|
|
let channel = ?wallet.openLedgerChannel(account.address, Asset)
|
|
peer.paymentChannel = channel.some
|
|
success channel
|
|
else:
|
|
failure "no account set for peer"
|
|
|
|
func pay*(wallet: WalletRef,
|
|
peer: BlockExcPeerCtx,
|
|
amount: UInt256): ?!SignedState =
|
|
if account =? peer.account:
|
|
let asset = Asset
|
|
let receiver = account.address
|
|
let channel = ?wallet.getOrOpenChannel(peer)
|
|
wallet.pay(channel, asset, receiver, amount)
|
|
else:
|
|
failure "no account set for peer"
|