Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
junwei0117 committed Apr 12, 2020
0 parents commit f836299
Show file tree
Hide file tree
Showing 10 changed files with 1,207 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
configs/config.json
8 changes: 8 additions & 0 deletions configs/config.json.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"QUORUM": {
"ENDPOINT": "http://localhost:22000"
},
"ACCOUNT":{
"PRIVATEKEY": "00000000000000000000000000000000000000000000000000000000000000000000"
}
}
258 changes: 258 additions & 0 deletions contracts/authority/authority.go

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions contracts/authority/deploy.go
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()
}
63 changes: 63 additions & 0 deletions contracts/metaTable/deploy.go
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()
}
479 changes: 479 additions & 0 deletions contracts/metaTable/metaTable.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions go.mod
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
)
288 changes: 288 additions & 0 deletions go.sum

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions main.go
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)
}
13 changes: 13 additions & 0 deletions readme.md
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.

0 comments on commit f836299

Please sign in to comment.