# sophon-gateway

The sophon-gateway is used for registering wallets, keeping track of miner-related information, and as a liaison between wallets and other components. It could be also used for proxy requests from chain services (shared modules/components) to independent modules/components.

# Start sophon-gateway

Download source code.

git clone https://github.com/ipfs-force-community/sophon-gateway.git

Compile.

make

Start service.

./sophon-gateway run

TIP

A successful startup will generate two files, config.toml and token, in the default repo directory ~/.sophon-gateway. Inside config.toml is the configuration item for sophon-gateway. token file is stored in JWT token, used for command execution.

# CLI Commands

Check help information.

./sophon-gateway -h

NAME:
   sophon-gateway - sophon-gateway for proxy incoming wallet and proof

USAGE:
   sophon-gateway [global options] command [command options] [arguments...]

VERSION:
   0.0.1'+gitc2048fb'

COMMANDS:
   run      start sophon-gateway daemon
   miner    miner cmds
   wallet   wallet cmds
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --listen value  host address and port the worker api will listen on (default: "/ip4/127.0.0.1/tcp/45132")
   --help, -h      show help (default: false)
   --version, -v   print the version (default: false)

# Notable commands

List all miners.

$ ./sophon-gateway miner list

# output
t01561
t02608
t02082

Check miner status.

$ ./sophon-gateway miner <MINER_ID>

# output
{
        "Connections": [
                {
                        "Channel": "ddbbd646-f3a2-474b-8457-ea7195cf5765",
                        "Ip": "127.0.0.1:36586",
                        "RequestCount": 0,
                        "CreateTime": "2021-07-20T17:34:33.767108581+08:00"
                }
        ],
        "ConnectionCount": 1
 }

List all wallets.

$ ./sophon-gateway wallet list

# output
[
        {
                "Account": "wallet_test1",
                "SupportAccounts": [
                        "testminer"
                ],
                "ConnectStates": [
                        {
                                "Addrs": [
                                        "t3wbwannykivspagunexwwky7eiqg4qa25eoqmgolpkzdz3fidocbjeflbyxqqguyypsekyhqbkj33f657ulla",
                                        "t1zkh45ooidf5zt3yv5o26uugjn5ao4fttsxfgdaq",
                                ],
                                "ChannelId": "016c1010-c56a-4849-89d1-e2b28aecc95a",
                                "Ip": "192.168.5.64:50448",
                                "RequestCount": 0,
                                "CreateTime": "2021-07-19T14:06:50.209609054+08:00"
                        }
                ]
        },
        {
                "Account": "wallet_test2",
                "SupportAccounts": [
                        "wallet_test2"
                ],
                "ConnectStates": [
                        {
                                "Addrs": [
                                        "t3vwbowhnkripgyxdawgwepcwcsqmai5exxetord362wudwr24a3kvgndnpsn6i3md2i23cmjx3rfflvbu7gna",
                                ],
                                "ChannelId": "57971a25-b760-4744-b6c2-af470ab456a9",
                                "Ip": "127.0.0.1:36598",
                                "RequestCount": 0,
                                "CreateTime": "2021-07-20T17:34:33.809502589+08:00"
                        }
                ]
        }
 ]

Check individual wallet.

$ ./sophon-gateway wallet <wallet-account>

# Check if wallet address exists

Every time gateway starts up, it will generate a random string (gateway_string). When a wallet tries to connect to gateway, it will carry a randomly generated string by itself (wallet_string). Gateway will then check each wallet address by calling sign interface with hash of gateway_string + wallet_string as payload. Through MsgMeta.Extra, gateway_string will also be transferred to wallet. And finally the result of wallet's sign will be validated by gateway.