Broadcast payment
This commit is contained in:
parent
6e7220efbb
commit
0897e615e6
|
@ -217,6 +217,15 @@ proc broadcastPricing*(network: BitswapNetwork,
|
||||||
let message = Message(pricing: PricingMessage.init(pricing))
|
let message = Message(pricing: PricingMessage.init(pricing))
|
||||||
asyncSpawn network.peers[id].send(message)
|
asyncSpawn network.peers[id].send(message)
|
||||||
|
|
||||||
|
proc broadcastPayment*(network: BitswapNetwork,
|
||||||
|
id: PeerId,
|
||||||
|
payment: SignedState) =
|
||||||
|
if id notin network.peers:
|
||||||
|
return
|
||||||
|
|
||||||
|
let message = Message(payment: StateChannelUpdate.init(payment))
|
||||||
|
asyncSpawn network.peers[id].send(message)
|
||||||
|
|
||||||
proc handlePayment(network: BitswapNetwork,
|
proc handlePayment(network: BitswapNetwork,
|
||||||
peer: NetworkPeer,
|
peer: NetworkPeer,
|
||||||
payment: SignedState) =
|
payment: SignedState) =
|
||||||
|
|
|
@ -238,3 +238,16 @@ suite "Bitswap Network - e2e":
|
||||||
network1.broadcastPricing(switch2.peerInfo.peerId, pricing)
|
network1.broadcastPricing(switch2.peerInfo.peerId, pricing)
|
||||||
|
|
||||||
await done.wait(100.millis)
|
await done.wait(100.millis)
|
||||||
|
|
||||||
|
test "broadcasts payment":
|
||||||
|
let payment = SignedState.example
|
||||||
|
|
||||||
|
proc handlePayment(peer: PeerID, received: SignedState) =
|
||||||
|
check received == payment
|
||||||
|
done.complete()
|
||||||
|
|
||||||
|
network2.handlers.onPayment = handlePayment
|
||||||
|
|
||||||
|
network1.broadcastPayment(switch2.peerInfo.peerId, payment)
|
||||||
|
|
||||||
|
await done.wait(100.millis)
|
||||||
|
|
Loading…
Reference in New Issue