Skip to content

Commit 454b73b

Browse files
authored
Merge pull request #8 from SmartPool/release-0.2.0
Release 0.2.0
2 parents 11f3cc0 + c6540c7 commit 454b73b

26 files changed

Lines changed: 732 additions & 208 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ _testmain.go
2222
*.exe
2323
*.test
2424
*.prof
25+
26+
build/_workspace
27+
build/bin
28+

README.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,71 @@
11
# Smartpool - The first decentralized mining pool based on smart contract (alpha)
22
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/SmartPool/Lobby)
33

4-
[Smartpool](http://smartpool.io) is [live on Kovan testnet](https://kovan.etherscan.io/address/0x0398ae5a974fe8179b6b0ab9baf4d5f366e932bf).
4+
## Ropsten testnet
5+
[Smartpool](http://smartpool.io) is [live on Ropsten testnet](https://ropsten.etherscan.io/address/0xf7d93bcb8e4372f46383ecee82f9adf1aa397ba9).
56
This repository consists of the client software.
67
The smart contract repository is [here](https://github.com/SmartPool/contracts).
78

8-
## Requirements
9-
### OS
9+
### Requirements
10+
#### OS
1011
The client is currently tested only on Mac OS and Ubuntu.
1112

12-
### Golang compiler
13-
[Golang compiler](https://golang.org/) version 1.6.2 or higher.
13+
#### Golang compiler
14+
[Golang compiler](https://golang.org/) version 1.7 or higher.
1415

15-
### Parity client
16+
#### Parity client
1617
[Ethereum Parity client](https://github.com/paritytech/parity/releases) version 1.5.9 or higher.
1718

18-
### Ethminer
19+
#### Geth client
20+
[Ethereum Geth client](https://github.com/ethereum/go-ethereum) needs to be compiled from source.
21+
22+
#### Ethminer
1923
We support CPU and GPU mining with [ethminer](https://github.com/ethereum/cpp-ethereum) version 1.2.9 or higher.
2024

21-
### ETH balance
22-
To run smartpool you must have a testnet Kovan account with least 0.5 Ether. You can get testnet Ethers from [faucets](https://github.com/kovan-testnet/faucet).
25+
#### ETH balance
26+
To run smartpool you must have a Ropsten testnet account with least 0.5 Ether. You can get testnet Ethers from [metamask faucets](https://faucet.metamask.io/) or ping us on our [gitter channel](https://gitter.im/SmartPool/Lobby).
27+
28+
*Note:* To get Ether from metamask faucet, you need to install metamask browser add-on.
2329

2430

25-
## Installation
31+
#### Installation
2632
1. `git clone https://github.com/SmartPool/smartpool-client.git`
2733
2. `cd smartpool-client`
2834
3. `./compile.sh`
2935

30-
## Running
31-
1. Run Parity on Kovan testnet. `parity --chain kovan`
32-
2. Run smartpool client `./smartpool --keystore keystore_path --miner account --spcontract 0x0398ae5a974FE8179B6B0ab9baF4d5f366E932Bf`
36+
### Running
37+
1. Run Geth on Ropsten testnet: `geth --testnet --fast --rpc --rpcapi "db,eth,net,web3,miner"` or Parity: `parity --chain ropsten --jsonrpc-apis "web3,eth,net,parity,traces,rpc,parity_set"`
38+
2. Run smartpool client `./smartpool --keystore keystore_path --miner account`.
39+
Where
40+
- `keystore_path` is a path to a directory that contains your account key. E.g., `$HOME/.local/share/io.parity.ethereum/keys/kovan/`.
41+
- `account` is the address of your account. E.g., `0x2ba80fe2811f8e0ea5eabf8e07697f7e9f5ae56c`.
42+
- E.g., `./smartpool --keystore ~/Library/Ethereum/testnet/keystore --miner 0xe034afdcc2ba0441ff215ee9ba0da3e86450108d`.
43+
3. Enter your key passphrase.
44+
4. Run `ethminer -F localhost:1633` or `ethminer -G -F localhost:1633` if you mine with your GPU.
45+
46+
## Kovan testnet
47+
48+
[Smartpool](http://smartpool.io) is also [live on Kovan testnet](https://kovan.etherscan.io/address/0x0398ae5a974fe8179b6b0ab9baf4d5f366e932bf).
49+
50+
### Parity client
51+
[Ethereum Parity client](https://github.com/paritytech/parity/releases) version 1.5.9 or higher.
52+
53+
### ETH balance
54+
To run smartpool you must have a testnet Kovan account with least 0.5 Ether. You can get testnet Ethers from [faucets](https://github.com/kovan-testnet/faucet).
55+
56+
### Installation
57+
1. `git clone https://github.com/SmartPool/smartpool-client.git`
58+
2. `cd smartpool-client`
59+
3. `./kovan_compile.sh`
60+
61+
### Running
62+
1. Run Parity on Kovan testnet. `parity --chain kovan --jsonrpc-apis "web3,eth,net,parity,traces,rpc,parity_set"`
63+
2. Run smartpool client `./kovan --keystore keystore_path --miner account --spcontract 0x0398ae5a974FE8179B6B0ab9baF4d5f366E932Bf`.
3364
Where
3465
- `keystore_path` is a path to a directory that contains your account key. E.g., `$HOME/.local/share/io.parity.ethereum/keys/kovan/`.
3566
- `account` is the address of your account. E.g., `0x2ba80fe2811f8e0ea5eabf8e07697f7e9f5ae56c`
3667
3. Enter your key passphrase.
37-
4. Run `ethminer -F localhost:1633`
68+
4. Run `ethminer -F localhost:1633` or `ethminer -G -F localhost:1633` if you mine with your GPU.
3869

3970
## Support
4071
Contact us at [gitter](https://gitter.im/SmartPool/Lobby) for support.

build/env.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
if [ ! -f "build/env.sh" ]; then
6+
echo "$0 must be run from the root of the repository."
7+
exit 2
8+
fi
9+
10+
# Create fake Go workspace if it doesn't exist yet.
11+
workspace="$PWD/build/_workspace"
12+
root="$PWD"
13+
spdir="$workspace/src/github.com/SmartPool"
14+
if [ ! -L "$spdir/smartpool-client" ]; then
15+
mkdir -p "$spdir"
16+
cd "$spdir"
17+
ln -s ../../../../../. smartpool-client
18+
cd "$root"
19+
fi
20+
21+
# Set up the environment to use the workspace.
22+
GOPATH="$workspace"
23+
export GOPATH
24+
25+
# Run the command inside the workspace.
26+
cd "$spdir/smartpool-client"
27+
PWD="$spdir/smartpool-client"
28+
29+
# Launch the arguments with the configured environment.
30+
exec "$@"

cmd/epoch/main.go

Lines changed: 142 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,32 @@ import (
77
"github.com/SmartPool/smartpool-client/ethereum/geth"
88
"github.com/ethereum/go-ethereum/common"
99
"golang.org/x/crypto/ssh/terminal"
10+
"gopkg.in/urfave/cli.v1"
1011
"math/big"
12+
"os"
1113
"syscall"
12-
"time"
1314
)
1415

15-
func Initialize() *smartpool.Input {
16-
// Setting
17-
rpcEndPoint := "http://localhost:8545"
18-
// keystorePath := "/Users/victor/Dropbox/Project/BlockChain/SmartPool/spclient_exp/.privatedata/keystore"
19-
keystorePath := "/Users/victor/Library/Application Support/io.parity.ethereum/keys/kovan"
20-
shareThreshold := 1
21-
shareDifficulty := big.NewInt(100000)
22-
submitInterval := 3 * time.Minute
16+
type Input struct {
17+
RpcEndPoint string
18+
KeystorePath string
19+
ContractAddr string
20+
MinerAddr string
21+
From uint
22+
To uint
23+
}
24+
25+
func Initialize(c *cli.Context) *Input {
26+
rpcEndPoint := c.String("rpc")
27+
keystorePath := c.String("keystore")
2328
contractAddr := "0x3dC682397e93E46EBb5bE7463658fdD658365e9D"
24-
minerAddr := "0x001aDBc838eDe392B5B054A47f8B8c28f2fA9F3F"
25-
extraData := ""
26-
return smartpool.NewInput(
27-
rpcEndPoint, keystorePath, shareThreshold, shareDifficulty,
28-
submitInterval, contractAddr, minerAddr, extraData, false,
29-
)
29+
minerAddr := c.String("account")
30+
from := c.Uint("from")
31+
to := c.Uint("to")
32+
return &Input{
33+
rpcEndPoint, keystorePath, contractAddr,
34+
minerAddr, from, to,
35+
}
3036
}
3137

3238
func promptUserPassPhrase(acc string) (string, error) {
@@ -41,34 +47,134 @@ func promptUserPassPhrase(acc string) (string, error) {
4147
}
4248
}
4349

44-
func main() {
45-
input := Initialize()
50+
func Run(c *cli.Context) error {
51+
input := Initialize(c)
52+
if input.KeystorePath == "" {
53+
fmt.Printf("You have to specify keystore path by --keystore. Abort!\n")
54+
return nil
55+
}
56+
smartpool.Output = &smartpool.StdOut{}
57+
address, ok, addresses := geth.GetAddress(
58+
input.KeystorePath,
59+
common.HexToAddress(input.MinerAddr),
60+
)
61+
if len(addresses) == 0 {
62+
fmt.Printf("We couldn't find any private keys in your keystore path.\n")
63+
fmt.Printf("Please make sure your keystore path exists.\nAbort!\n")
64+
return nil
65+
}
66+
fmt.Printf("Using miner address: %s\n", address.Hex())
67+
input.MinerAddr = address.Hex()
4668
gethRPC, _ := geth.NewGethRPC(
47-
input.RPCEndpoint(), input.ContractAddress(),
48-
input.ExtraData(), input.ShareDifficulty(),
69+
input.RpcEndPoint, input.ContractAddr,
70+
"", big.NewInt(1),
71+
)
72+
client, err := gethRPC.ClientVersion()
73+
if err != nil {
74+
fmt.Printf("Node RPC server is unavailable.\n")
75+
fmt.Printf("Make sure you have Parity or Geth running.\n")
76+
return err
77+
}
78+
fmt.Printf("Connected to Ethereum node: %s\n", client)
79+
ethereumPoolMonitor, err := geth.NewPoolMonitor(
80+
common.HexToAddress(input.ContractAddr),
81+
smartpool.VERSION,
82+
input.RpcEndPoint,
4983
)
84+
if err != nil {
85+
fmt.Printf("Couln't connect to gateway.\n")
86+
return err
87+
}
88+
input.ContractAddr = ethereumPoolMonitor.ContractAddress().Hex()
89+
fmt.Printf("Epoch data will be submitted to contract at %s\n", input.ContractAddr)
5090
var gethContractClient *geth.GethContractClient
51-
var err error
5291
for {
53-
passphrase, _ := promptUserPassPhrase(
54-
input.MinerAddress(),
55-
)
56-
gethContractClient, err = geth.NewGethContractClient(
57-
common.HexToAddress(input.ContractAddress()), gethRPC,
58-
common.HexToAddress(input.MinerAddress()),
59-
input.RPCEndpoint(), input.KeystorePath(), passphrase,
60-
)
61-
if gethContractClient != nil {
62-
break
92+
if ok {
93+
passphrase, _ := promptUserPassPhrase(
94+
input.MinerAddr,
95+
)
96+
gethContractClient, err = geth.NewGethContractClient(
97+
common.HexToAddress(input.ContractAddr), gethRPC,
98+
common.HexToAddress(input.MinerAddr),
99+
input.RpcEndPoint, input.KeystorePath, passphrase,
100+
)
101+
if gethContractClient != nil {
102+
break
103+
} else {
104+
fmt.Printf("error: %s\n", err)
105+
}
63106
} else {
64-
fmt.Printf("error: %s\n", err)
107+
if input.KeystorePath == "" {
108+
fmt.Printf("You have to specify keystore path by --keystore. Abort!\n")
109+
} else {
110+
fmt.Printf("Your keystore: %s\n", input.KeystorePath)
111+
fmt.Printf("Your miner address: %s\n", input.MinerAddr)
112+
if len(addresses) > 0 {
113+
fmt.Printf("We couldn't find the private key of your miner address in the keystore path you specified. We found following addresses:\n")
114+
for i, addr := range addresses {
115+
fmt.Printf("%d. %s\n", i+1, addr.Hex())
116+
}
117+
fmt.Printf("Please make sure you entered correct miner address.\n")
118+
} else {
119+
fmt.Printf("We couldn't find any private keys in your keystore path.\n")
120+
fmt.Printf("Please make sure your keystore path exists.\nAbort!\n")
121+
}
122+
}
123+
return nil
65124
}
66125
}
67126
ethereumContract := ethereum.NewContract(gethContractClient)
68-
err = ethereumContract.SetEpochData(8, 9, 10, 11, 12, 13, 14, 15)
69-
if err != nil {
70-
fmt.Printf("Got error: %v\n", err)
71-
} else {
72-
fmt.Printf("Succeeded.\n", err)
127+
var epochs = []int{}
128+
for i := int(input.From); i <= int(input.To); i++ {
129+
epochs = append(epochs, i)
130+
if len(epochs) == 10 || i == int(input.To) {
131+
fmt.Printf("Calculating epoch datas for epochs number %v...\n", epochs)
132+
err = ethereumContract.SetEpochData(epochs...)
133+
if err != nil {
134+
fmt.Printf("Got error: %s\n", err)
135+
} else {
136+
fmt.Printf("Succeeded.\n")
137+
}
138+
epochs = []int{}
139+
}
73140
}
141+
return nil
142+
}
143+
144+
func BuildAppCommandLine() *cli.App {
145+
app := cli.NewApp()
146+
app.Description = "Commandline tool to calculate and submit epoch data for SmartPool"
147+
app.Name = "SmartPool epoch tool"
148+
app.Usage = "Submit epoch data to contract"
149+
app.Version = smartpool.VERSION
150+
app.Flags = []cli.Flag{
151+
cli.StringFlag{
152+
Name: "rpc",
153+
Value: "http://localhost:8545",
154+
Usage: "RPC endpoint of Ethereum node",
155+
},
156+
cli.StringFlag{
157+
Name: "keystore",
158+
Usage: "Keystore path to your ethereum account private key. SmartPool will look for private key of the miner address you specified in that path.",
159+
},
160+
cli.StringFlag{
161+
Name: "account",
162+
Usage: "The address that is used to submit epoch data (Default: First account in your keystore.)",
163+
},
164+
cli.UintFlag{
165+
Name: "from",
166+
Usage: "Starting epoch number to calculate epoch data on.",
167+
},
168+
cli.UintFlag{
169+
Name: "to",
170+
Usage: "Ending epoch number to calculate epoch data on.",
171+
},
172+
}
173+
app.Action = Run
174+
return app
175+
}
176+
177+
func main() {
178+
app := BuildAppCommandLine()
179+
app.Run(os.Args)
74180
}

cmd/kovan/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ func Run(c *cli.Context) error {
156156
ethereumPoolMonitor,
157157
ethereumWorkPool, ethereumNetworkClient,
158158
ethereumClaimRepo, ethereumContract,
159+
common.HexToAddress(input.ContractAddress()),
159160
common.HexToAddress(input.MinerAddress()),
160-
input.SubmitInterval(), input.ShareThreshold(),
161-
input.HotStop(),
161+
input.ExtraData(), input.SubmitInterval(),
162+
input.ShareThreshold(), input.HotStop(),
162163
)
163164
server := ethminer.NewRPCServer(
164165
smartpool.Output,

0 commit comments

Comments
 (0)