rename to eccfaucet
This commit is contained in:
parent
dfddc743d7
commit
c8cb78e760
14
.envtemplate
14
.envtemplate
|
@ -1,7 +1,7 @@
|
||||||
ZFAUCET_RPCUSER=zcashrpc
|
ECCFAUCET_RPCUSER=zcashrpc
|
||||||
ZFAUCET_RPCPASSWORD=notsecure
|
ECCFAUCET_RPCPASSWORD=notsecure
|
||||||
ZFAUCET_RPCHOST=192.168.86.46
|
ECCFAUCET_RPCHOST=192.168.86.46
|
||||||
ZFAUCET_RPCPORT=38237
|
ECCFAUCET_RPCPORT=38237
|
||||||
ZFAUCET_LISTENPORT=3000
|
ECCFAUCET_LISTENPORT=3000
|
||||||
ZFAUCET_LISTENADDRESS=127.0.0.1
|
ECCFAUCET_LISTENADDRESS=127.0.0.1
|
||||||
ZFAUCET_FUNDINGADDRESS=
|
ECCFAUCET_FUNDINGADDRESS=
|
|
@ -4,7 +4,7 @@ version: '2'
|
||||||
services:
|
services:
|
||||||
zcashd:
|
zcashd:
|
||||||
image: electriccoinco/zcashd:latest
|
image: electriccoinco/zcashd:latest
|
||||||
command: "-equihashsolver=tromp -genproclimit=1 -mineraddress=$ZFAUCET_FUNDINGADDRESS"
|
command: "-equihashsolver=tromp -genproclimit=1 -mineraddress=$ECCFAUCET_FUNDINGADDRESS"
|
||||||
volumes:
|
volumes:
|
||||||
- $ZCASHD_DATADIR:/srv/zcashd/.zcash
|
- $ZCASHD_DATADIR:/srv/zcashd/.zcash
|
||||||
- $ZCASHD_PARMDIR:/srv/zcashd/.zcash-params
|
- $ZCASHD_PARMDIR:/srv/zcashd/.zcash-params
|
||||||
|
@ -13,10 +13,10 @@ services:
|
||||||
mem_limit: 6G
|
mem_limit: 6G
|
||||||
ports:
|
ports:
|
||||||
- "127.0.0.1:$ZCASHD_RPCPORT:$ZCASHD_RPCPORT"
|
- "127.0.0.1:$ZCASHD_RPCPORT:$ZCASHD_RPCPORT"
|
||||||
zfaucet:
|
eccfaucet:
|
||||||
image: doubtingben/zfaucet
|
image: electriccoinco/eccfaucet
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
mem_limit: 512M
|
mem_limit: 512M
|
||||||
ports:
|
ports:
|
||||||
- "$ZFAUCET_LISTENPORT:$ZFAUCET_LISTENPORT"
|
- "$ECCFAUCET_LISTENPORT:$ECCFAUCET_LISTENPORT"
|
||||||
|
|
64
main.go
64
main.go
|
@ -31,7 +31,7 @@ type TapRequest struct {
|
||||||
WalletAddress string
|
WalletAddress string
|
||||||
RequestedAt time.Time
|
RequestedAt time.Time
|
||||||
}
|
}
|
||||||
type ZfaucetConfig struct {
|
type ECCfaucetConfig struct {
|
||||||
ListenPort string
|
ListenPort string
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
RPCUser string
|
RPCUser string
|
||||||
|
@ -41,27 +41,27 @@ type ZfaucetConfig struct {
|
||||||
FundingAddress string
|
FundingAddress string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zConfig *ZfaucetConfig) checkConfig() error {
|
func (c *ECCfaucetConfig) checkConfig() error {
|
||||||
if zConfig.ListenPort == "" {
|
if c.ListenPort == "" {
|
||||||
zConfig.ListenPort = "3000"
|
c.ListenPort = "3000"
|
||||||
}
|
}
|
||||||
if zConfig.ListenAddress == "" {
|
if c.ListenAddress == "" {
|
||||||
zConfig.ListenPort = "127.0.0.1"
|
c.ListenPort = "127.0.0.1"
|
||||||
}
|
}
|
||||||
if zConfig.RPCHost == "" {
|
if c.RPCHost == "" {
|
||||||
zConfig.ListenPort = "localhost"
|
c.ListenPort = "localhost"
|
||||||
}
|
}
|
||||||
if zConfig.ListenPort == "" {
|
if c.ListenPort == "" {
|
||||||
zConfig.ListenPort = "3000"
|
c.ListenPort = "3000"
|
||||||
}
|
}
|
||||||
if zConfig.FundingAddress == "" {
|
if c.FundingAddress == "" {
|
||||||
return fmt.Errorf("ZFAUCET_FUNDINGADDRESS is required")
|
return fmt.Errorf("ECCFAUCET_FUNDINGADDRESS is required")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zfaucet holds a zfaucet configuration
|
// ECCFaucet holds a zfaucet configuration
|
||||||
type Zfaucet struct {
|
type ECCFaucet struct {
|
||||||
RPCConnetion jsonrpc.RPCClient
|
RPCConnetion jsonrpc.RPCClient
|
||||||
CurrentHeight int
|
CurrentHeight int
|
||||||
UpdatedChainInfo time.Time
|
UpdatedChainInfo time.Time
|
||||||
|
@ -72,7 +72,7 @@ type Zfaucet struct {
|
||||||
FundingAddress string
|
FundingAddress string
|
||||||
TapRequests []*TapRequest
|
TapRequests []*TapRequest
|
||||||
TapCache *cache2go.CacheTable
|
TapCache *cache2go.CacheTable
|
||||||
ZfaucetHTML string
|
HomeHTML string
|
||||||
}
|
}
|
||||||
|
|
||||||
type SendAmount struct {
|
type SendAmount struct {
|
||||||
|
@ -86,7 +86,7 @@ type SendAmountMemo struct {
|
||||||
Memo string
|
Memo string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zfaucet) ClearCache() {
|
func (z *ECCFaucet) ClearCache() {
|
||||||
for {
|
for {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
fmt.Printf("Clearing cache: %d\n", len(z.TapRequests))
|
fmt.Printf("Clearing cache: %d\n", len(z.TapRequests))
|
||||||
|
@ -101,7 +101,7 @@ func (z *Zfaucet) ClearCache() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zfaucet) UpdateZcashInfo() {
|
func (z *ECCFaucet) UpdateZcashInfo() {
|
||||||
for {
|
for {
|
||||||
z.UpdatedChainInfo = time.Now()
|
z.UpdatedChainInfo = time.Now()
|
||||||
zChainInfo, err := getBlockchainInfo(z.RPCConnetion)
|
zChainInfo, err := getBlockchainInfo(z.RPCConnetion)
|
||||||
|
@ -122,7 +122,7 @@ func (z *Zfaucet) UpdateZcashInfo() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zfaucet) WaitForOperation(opid string) (os OperationStatus, err error) {
|
func (z *ECCFaucet) WaitForOperation(opid string) (os OperationStatus, err error) {
|
||||||
var opStatus []struct {
|
var opStatus []struct {
|
||||||
CreationTime int `json:"creation_time"`
|
CreationTime int `json:"creation_time"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -165,14 +165,14 @@ func (z *Zfaucet) WaitForOperation(opid string) (os OperationStatus, err error)
|
||||||
return os, errors.New("Timeout waiting for operations status")
|
return os, errors.New("Timeout waiting for operations status")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zfaucet) ValidateFundingAddress() (bool, error) {
|
func (z *ECCFaucet) ValidateFundingAddress() (bool, error) {
|
||||||
if z.FundingAddress == "" {
|
if z.FundingAddress == "" {
|
||||||
return false, errors.New("FundingAddressis required")
|
return false, errors.New("FundingAddressis required")
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z *Zfaucet) ZSendManyFaucet(remoteAddr string, remoteWallet string) (opStatus OperationStatus, err error) {
|
func (z *ECCFaucet) ZSendManyFaucet(remoteAddr string, remoteWallet string) (opStatus OperationStatus, err error) {
|
||||||
var op *string
|
var op *string
|
||||||
amountEntry := SendAmount{
|
amountEntry := SendAmount{
|
||||||
Address: remoteWallet,
|
Address: remoteWallet,
|
||||||
|
@ -238,7 +238,7 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
var zConfig ZfaucetConfig
|
var zConfig ECCfaucetConfig
|
||||||
err := envconfig.Process("zfaucet", &zConfig)
|
err := envconfig.Process("zfaucet", &zConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err.Error())
|
log.Fatal(err.Error())
|
||||||
|
@ -249,7 +249,7 @@ func main() {
|
||||||
fmt.Printf("zfaucet: %#v\n", zConfig)
|
fmt.Printf("zfaucet: %#v\n", zConfig)
|
||||||
|
|
||||||
basicAuth := base64.StdEncoding.EncodeToString([]byte(zConfig.RPCUser + ":" + zConfig.RPCPassword))
|
basicAuth := base64.StdEncoding.EncodeToString([]byte(zConfig.RPCUser + ":" + zConfig.RPCPassword))
|
||||||
var z Zfaucet
|
var z ECCFaucet
|
||||||
z.TapCache = cache2go.Cache("tapRequests")
|
z.TapCache = cache2go.Cache("tapRequests")
|
||||||
z.FundingAddress = zConfig.FundingAddress
|
z.FundingAddress = zConfig.FundingAddress
|
||||||
z.Operations = make(map[string]OperationStatus)
|
z.Operations = make(map[string]OperationStatus)
|
||||||
|
@ -263,7 +263,7 @@ func main() {
|
||||||
go z.UpdateZcashInfo()
|
go z.UpdateZcashInfo()
|
||||||
|
|
||||||
box := packr.NewBox("./templates")
|
box := packr.NewBox("./templates")
|
||||||
z.ZfaucetHTML, err = box.FindString("zfaucet.html")
|
z.HomeHTML, err = box.FindString("eccfaucet.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -290,10 +290,10 @@ type OperationStatus struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// home is the default request handler
|
// home is the default request handler
|
||||||
func (z *Zfaucet) home(w http.ResponseWriter, r *http.Request) {
|
func (z *ECCFaucet) home(w http.ResponseWriter, r *http.Request) {
|
||||||
// tData is the html template data
|
// tData is the html template data
|
||||||
tData := struct {
|
tData := struct {
|
||||||
Z *Zfaucet
|
Z *ECCFaucet
|
||||||
Msg string
|
Msg string
|
||||||
}{
|
}{
|
||||||
z,
|
z,
|
||||||
|
@ -321,7 +321,7 @@ func (z *Zfaucet) home(w http.ResponseWriter, r *http.Request) {
|
||||||
tData.Msg = fmt.Sprintf("Successfully submitted operation, transaction: %s", opStatus.TxID)
|
tData.Msg = fmt.Sprintf("Successfully submitted operation, transaction: %s", opStatus.TxID)
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
tmpl, err := template.New("name").Parse(z.ZfaucetHTML)
|
tmpl, err := template.New("name").Parse(z.HomeHTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
}
|
}
|
||||||
|
@ -329,7 +329,7 @@ func (z *Zfaucet) home(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// OKMiddleware determines if a request is allowed before execution
|
// OKMiddleware determines if a request is allowed before execution
|
||||||
func (z *Zfaucet) OKMiddleware(next http.Handler) http.Handler {
|
func (z *ECCFaucet) OKMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Our middleware logic goes here...
|
// Our middleware logic goes here...
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
|
@ -337,7 +337,7 @@ func (z *Zfaucet) OKMiddleware(next http.Handler) http.Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Balance
|
// Balance
|
||||||
func (z *Zfaucet) balance(w http.ResponseWriter, r *http.Request) {
|
func (z *ECCFaucet) balance(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
var totalBalance *z_gettotalbalance
|
var totalBalance *z_gettotalbalance
|
||||||
if err := z.RPCConnetion.CallFor(&totalBalance, "z_gettotalbalance"); err != nil {
|
if err := z.RPCConnetion.CallFor(&totalBalance, "z_gettotalbalance"); err != nil {
|
||||||
|
@ -353,10 +353,10 @@ func (z *Zfaucet) balance(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// opsStatus
|
// opsStatus
|
||||||
func (z *Zfaucet) opsStatus(w http.ResponseWriter, r *http.Request) {
|
func (z *ECCFaucet) opsStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
// tData is the html template data
|
// tData is the html template data
|
||||||
tData := struct {
|
tData := struct {
|
||||||
Z *Zfaucet
|
Z *ECCFaucet
|
||||||
Ops *[]string
|
Ops *[]string
|
||||||
Type string
|
Type string
|
||||||
}{
|
}{
|
||||||
|
@ -369,7 +369,7 @@ func (z *Zfaucet) opsStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Header().Set("Content-Type", "text/html")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
tmpl, err := template.New("name").Parse(z.ZfaucetHTML)
|
tmpl, err := template.New("name").Parse(z.HomeHTML)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ func (z *Zfaucet) opsStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// addresses
|
// addresses
|
||||||
func (z *Zfaucet) addresses(w http.ResponseWriter, r *http.Request) {
|
func (z *ECCFaucet) addresses(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
var addresses []WalletAddress
|
var addresses []WalletAddress
|
||||||
var zlist *[]string
|
var zlist *[]string
|
||||||
|
|
Loading…
Reference in New Issue