Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ ADMINS=your;email;address
ETH_URL=http://ganache:8545
ETH_DEPLOY=true
ETH_PRIVATE_KEY=0x6f1313062db38875fb01ee52682cbf6a8420e92bfbc578c5d4fdc0a32c50266f
ETH_CONTRACT=
ETH_DAA_CONTRACT=
ETH_PAYOUT_CONTRACT=
ETH_MEMBERSHIP_CONTRACT=
ETH_WALLET_CONTRACT=

#NEO settings
NEO_URL=http://seed1.neo.org:10332
Expand Down
18 changes: 12 additions & 6 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (
)

type Config struct {
PayoutContractAddress string `json:"payoutContractAddress"`
ChainId int64 `json:"chainId"`
Env string `json:"env"`
MembershipContractAddress string `json:"membershipContractAddress"`
DaaContractAddress string `json:"daaContractAddress"`
WalletContractAddress string `json:"walletContractAddress"`
PayoutContractAddress string `json:"payoutContractAddress"`
ChainId int64 `json:"chainId"`
Env string `json:"env"`
}

type PayoutRequest2 struct {
Expand Down Expand Up @@ -107,9 +110,12 @@ func timeWarp(w http.ResponseWriter, r *http.Request, _ string) {

func config(w http.ResponseWriter, _ *http.Request) {
cfg := Config{
PayoutContractAddress: opts.Ethereum.Contract,
ChainId: ethClient.chainId.Int64(),
Env: opts.Env,
MembershipContractAddress: opts.Ethereum.MembershipContract,
DaaContractAddress: opts.Ethereum.DaaContract,
WalletContractAddress: opts.Ethereum.WalletContract,
PayoutContractAddress: opts.Ethereum.PayoutContract,
ChainId: ethClient.chainId.Int64(),
Env: opts.Env,
}
writeJson(w, cfg)
}
Expand Down
2 changes: 1 addition & 1 deletion eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func getEthClient(ethUrl string, hexPrivateKey string, deploy bool, ethContract
log.Printf("Start deploying ETH Contract...")
var addr common.Address
c.contract, addr = deployEthContract(c, *parsed)
opts.Ethereum.Contract = addr.Hex()
opts.Ethereum.PayoutContract = addr.Hex()
} else {
c.contract = bind.NewBoundContract(common.HexToAddress(ethContract), *parsed, c.c, c.c, c.c)
}
Expand Down
25 changes: 19 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,29 @@ type Timewarp struct {
Offset int `json:"offset"`
}

type Blockchain struct {
type NeoBlockchain struct {
Contract string
PrivateKey string
Url string
Deploy bool
}

type EthBlockchain struct {
DaaContract string
MembershipContract string
WalletContract string
PayoutContract string
PrivateKey string
Url string
Deploy bool
}

type Opts struct {
Port int
Env string
HS256 string
Ethereum Blockchain
NEO Blockchain
Ethereum EthBlockchain
NEO NeoBlockchain
Admins string
}

Expand All @@ -67,7 +77,10 @@ func NewOpts() *Opts {
9084), "listening HTTP port")
flag.StringVar(&o.HS256, "hs256", lookupEnv("HS256"), "HS256 key")
flag.StringVar(&o.Ethereum.PrivateKey, "eth-private-key", lookupEnv("ETH_PRIVATE_KEY"), "Ethereum private key")
flag.StringVar(&o.Ethereum.Contract, "eth-contract", lookupEnv("ETH_CONTRACT"), "Ethereum contract address")
flag.StringVar(&o.Ethereum.PayoutContract, "eth-payout-contract", lookupEnv("ETH_PAYOUT_CONTRACT"), "Ethereum payout contract address")
flag.StringVar(&o.Ethereum.WalletContract, "eth-wallet-contract", lookupEnv("ETH_WALLET_CONTRACT"), "Ethereum wallet contract address")
flag.StringVar(&o.Ethereum.MembershipContract, "eth-membership-contract", lookupEnv("ETH_MEMBERSHIP_CONTRACT"), "Ethereum membership contract address")
flag.StringVar(&o.Ethereum.DaaContract, "eth-dao-contract", lookupEnv("ETH_DAA_CONTRACT"), "Ethereum DAO contract address")
flag.StringVar(&o.Ethereum.Url, "eth-url", lookupEnv("ETH_URL"), "Ethereum URL")
flag.BoolVar(&o.Ethereum.Deploy, "eth-deploy", lookupEnv("ETH_DEPLOY") == "true", "Set to true to deploy ETH contract")
flag.StringVar(&o.NEO.PrivateKey, "neo-private-key", lookupEnv("NEO_PRIVATE_KEY"), "NEO private key")
Expand Down Expand Up @@ -139,10 +152,10 @@ func lookupEnvInt(key string, defaultValues ...int) int {

func ethInit() *ClientETH {
now := time.Now()
ethClient, err := getEthClient(opts.Ethereum.Url, opts.Ethereum.PrivateKey, opts.Ethereum.Deploy, opts.Ethereum.Contract)
ethClient, err := getEthClient(opts.Ethereum.Url, opts.Ethereum.PrivateKey, opts.Ethereum.Deploy, opts.Ethereum.PayoutContract)
for err != nil && now.Add(time.Duration(10)*time.Second).After(time.Now()) {
time.Sleep(time.Second)
ethClient, err = getEthClient(opts.Ethereum.Url, opts.Ethereum.PrivateKey, opts.Ethereum.Deploy, opts.Ethereum.Contract)
ethClient, err = getEthClient(opts.Ethereum.Url, opts.Ethereum.PrivateKey, opts.Ethereum.Deploy, opts.Ethereum.PayoutContract)
}
if err != nil {
log.Fatal("Could not initialize ETH network", err)
Expand Down