From b9389909b0f216c1a57ac1dc8af18f80951623c8 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Sun, 20 Oct 2024 11:41:07 +0700 Subject: [PATCH] Create ChannelManager.sol --- .../state-channels/ChannelManager.sol | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 blockchain_integration/pi_network/pi-network-layer2-scaling/contracts/state-channels/ChannelManager.sol diff --git a/blockchain_integration/pi_network/pi-network-layer2-scaling/contracts/state-channels/ChannelManager.sol b/blockchain_integration/pi_network/pi-network-layer2-scaling/contracts/state-channels/ChannelManager.sol new file mode 100644 index 000000000..e3be6767b --- /dev/null +++ b/blockchain_integration/pi_network/pi-network-layer2-scaling/contracts/state-channels/ChannelManager.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import "./StateChannel.sol"; + +contract ChannelManager { + mapping(address => mapping(address => StateChannel)) public channels; + event ChannelCreated(address indexed participantA, address indexed participantB, address channelAddress); + + function createChannel(address _participantB) external { + require(_participantB != msg.sender, "Cannot create channel with self"); + StateChannel channel = new StateChannel(msg.sender, _participantB, address(this)); + channels[msg.sender][_participantB] = channel; + emit ChannelCreated(msg.sender, _participantB, address(channel)); + } + + function getChannel(address _participantA, address _participantB) external view returns (StateChannel) { + return channels[_participantA][_participantB]; + } +}