-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f836299
Showing
10 changed files
with
1,207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
configs/config.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"QUORUM": { | ||
"ENDPOINT": "http://localhost:22000" | ||
}, | ||
"ACCOUNT":{ | ||
"PRIVATEKEY": "00000000000000000000000000000000000000000000000000000000000000000000" | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package authority | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"log" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Deploy() (string, string) { | ||
quorumEndpoint := viper.GetString(`QUORUM.ENDPOINT`) | ||
privatekeyHex := viper.GetString(`ACCOUNT.PRIVATEKEY`) | ||
|
||
var address common.Address | ||
var transaction *types.Transaction | ||
|
||
quorumClient, err := ethclient.Dial(quorumEndpoint) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
privateKey, err := crypto.HexToECDSA(privatekeyHex) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
publicKey := privateKey.Public() | ||
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) | ||
if !ok { | ||
log.Fatal(err) | ||
} | ||
|
||
accountAddress := crypto.PubkeyToAddress(*publicKeyECDSA) | ||
|
||
nonce, err := quorumClient.PendingNonceAt(context.Background(), accountAddress) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
gasPrice, err := quorumClient.SuggestGasPrice(context.Background()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
auth := bind.NewKeyedTransactor(privateKey) | ||
auth.Nonce = big.NewInt(int64(nonce)) | ||
auth.Value = big.NewInt(0) | ||
auth.GasLimit = uint64(5000000) | ||
auth.GasPrice = gasPrice | ||
|
||
address, transaction, _, err = DeployAuthority(auth, quorumClient) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return address.Hex(), transaction.Hash().Hex() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package metaTable | ||
|
||
import ( | ||
"context" | ||
"crypto/ecdsa" | ||
"log" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/accounts/abi/bind" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/types" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"github.com/ethereum/go-ethereum/ethclient" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Deploy() (string, string) { | ||
quorumEndpoint := viper.GetString(`QUORUM.ENDPOINT`) | ||
privatekeyHex := viper.GetString(`ACCOUNT.PRIVATEKEY`) | ||
|
||
var address common.Address | ||
var transaction *types.Transaction | ||
|
||
quorumClient, err := ethclient.Dial(quorumEndpoint) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
privateKey, err := crypto.HexToECDSA(privatekeyHex) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
publicKey := privateKey.Public() | ||
publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) | ||
if !ok { | ||
log.Fatal(err) | ||
} | ||
|
||
accountAddress := crypto.PubkeyToAddress(*publicKeyECDSA) | ||
|
||
nonce, err := quorumClient.PendingNonceAt(context.Background(), accountAddress) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
gasPrice, err := quorumClient.SuggestGasPrice(context.Background()) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
auth := bind.NewKeyedTransactor(privateKey) | ||
auth.Nonce = big.NewInt(int64(nonce)) | ||
auth.Value = big.NewInt(0) | ||
auth.GasLimit = uint64(5000000) | ||
auth.GasPrice = gasPrice | ||
|
||
address, transaction, _, err = DeployMetaTable(auth, quorumClient) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
return address.Hex(), transaction.Hash().Hex() | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module github.com/DropKit/Require-Deployer | ||
|
||
go 1.14 | ||
|
||
require ( | ||
github.com/ethereum/go-ethereum v1.9.12 | ||
github.com/spf13/viper v1.6.3 | ||
) |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/DropKit/Require-Deployer/contracts/authority" | ||
"github.com/DropKit/Require-Deployer/contracts/metaTable" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func init() { | ||
viper.SetConfigName("config") | ||
viper.AddConfigPath("./configs") | ||
err := viper.ReadInConfig() | ||
if err != nil { | ||
print(err) | ||
} | ||
} | ||
|
||
func main() { | ||
metaTableAddr, _ := metaTable.Deploy() | ||
log.Print("MetaTable Address: " + metaTableAddr) | ||
|
||
authorityAddr, _ := authority.Deploy() | ||
log.Print("Auhority Address: " + authorityAddr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# DropKit Require Deployer | ||
|
||
## Prerequisites | ||
|
||
- Go >= 1.13 | ||
|
||
## Deploy Require Smart Contract | ||
|
||
```bash | ||
go run main.go | ||
``` | ||
|
||
The output will show `metaTable` and `Authority` smart contract address. |