Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: merge develop to releases/v1.2.0 #1227

Merged
merged 31 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fcced07
feat: Github Migration (#1146)
yohanelly95 Oct 12, 2023
8f486d3
Update develop.yml (#1148)
SkandaBhat Oct 12, 2023
2ae4f4f
Update develop.yml (#1149)
SkandaBhat Oct 12, 2023
d7826c1
Update develop.yml
SkandaBhat Oct 12, 2023
952594e
Update develop.yml
SkandaBhat Oct 12, 2023
dbd5950
Update develop.yml
SkandaBhat Oct 12, 2023
6aef029
Fix go mod tidy
Oct 12, 2023
37e0b63
Replaced curve instance elliptic.P256() with crypto.S256() (#1150)
Yashk767 Oct 13, 2023
f1d7d35
fix: Update Dockerfile with version bumps (#1152)
yohanelly95 Oct 13, 2023
211182d
Feature/v1.1.0 (#1154)
SkandaBhat Oct 18, 2023
768f265
feat: Publish to Dockerhub on every merge to develop and release (#1…
yohanelly95 Oct 23, 2023
7dbcc88
Set version meta to empty string (#1159)
Yashk767 Oct 25, 2023
ab83868
Yash/raz 528 npm run build all fails with new update chainid script (…
Yashk767 Oct 26, 2023
917d46a
Merge branch 'main' into develop
Oct 26, 2023
aea43d5
fix: update branch pattern (#1162)
SkandaBhat Oct 26, 2023
0dc7960
fix: conversion of hex to decimal (#1167)
Yashk767 Nov 28, 2023
703aec5
fix: conversion of hex to decimal (#1167) (#1169)
Yashk767 Dec 11, 2023
3bf2914
feat: added support for job returning results in hex array (#1174)
Yashk767 Dec 20, 2023
d076432
refactor: used hash of url and body as a cache key (#1176)
Yashk767 Jan 5, 2024
2bab695
fix: conversion of hex to decimal (#1167) (#1169) (#1178)
Yashk767 Jan 15, 2024
d8a72ec
chore: merge releases/v1.1.0 into develop
Yashk767 Jan 15, 2024
0362b02
chore: merge releases/v1.1.0 into develop
Yashk767 Jan 16, 2024
8aac72a
release: v1.1.1-dev (#1190)
Yashk767 Feb 21, 2024
2fd96c8
fix: incorrect state error for shorter epoch length (#1192)
Yashk767 Mar 1, 2024
5ae7e15
revert: fetching jobs/collections from cache (#1198)
Yashk767 Mar 22, 2024
e210cf5
revert: median concurrency changes (#1213)
Yashk767 Jun 13, 2024
f619148
feat: added support for APIs responding in json array (#1216)
Yashk767 Jul 2, 2024
89d1552
chore: merge updates from main to develop branch
Yashk767 Aug 7, 2024
12d57a1
chore: merge v1.1.0-patch.1 release changes from main into develop
Yashk767 Aug 9, 2024
07cf9fe
chore: merge feature/v1.2.0 dev release to develop (#1224)
Yashk767 Aug 9, 2024
7f77a9f
refactor: requested changes in refactoring and default values for v1.…
Yashk767 Sep 3, 2024
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
4 changes: 4 additions & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ on:
push:
branches:
- "develop"
pull_request:
branches:
- "feature/*"

jobs:
test:
Expand Down Expand Up @@ -71,6 +74,7 @@ jobs:
action: persist

push-docker-build:
if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/develop')
runs-on: ubuntu-latest
needs: test
steps:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ docker exec -it razor-go razor setConfig --provider <rpc_provider> --alternatePr
Example:

```
$ ./razor setConfig --provider https://mainnet.skalenodes.com/v1/turbulent-unique-scheat --alternateProvider https://ce2m-skale.chainode.tech:10200/ --gasmultiplier 1 --buffer 20 --wait 30 --gasprice 0 --logLevel debug --gasLimit 2 --rpcTimeout 10 --httpTimeout 10 --logFileMaxSize 200 --logFileMaxBackups 52 --logFileMaxAge 365
$ ./razor setConfig --provider https://mainnet.skalenodes.com/v1/turbulent-unique-scheat --alternateProvider https://ce2m-skale.chainode.tech:10200/ --gasmultiplier 1 --buffer 20 --wait 30 --gasprice 0 --logLevel debug --gasLimit 2 --rpcTimeout 10 --httpTimeout 10 --logFileMaxSize 200 --logFileMaxBackups 10 --logFileMaxAge 60
```

Besides, setting these parameters in the config, you can use different values for these parameters in various commands. Just add the same flag to any command you want to use and the new config changes will appear for that command.
Expand Down
58 changes: 14 additions & 44 deletions accounts/accountUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,26 @@
package accounts

import (
"crypto/ecdsa"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
"os"
"razor/core/types"
)

//go:generate mockery --name AccountInterface --output ./mocks/ --case=underscore

var AccountUtilsInterface AccountInterface

type AccountInterface interface {
CreateAccount(path string, password string) accounts.Account
GetPrivateKeyFromKeystore(keystorePath string, password string) (*ecdsa.PrivateKey, error)
GetPrivateKey(address string, password string, keystorePath string) (*ecdsa.PrivateKey, error)
SignData(hash []byte, account types.Account, defaultPath string) ([]byte, error)
Accounts(path string) []accounts.Account
NewAccount(path string, passphrase string) (accounts.Account, error)
DecryptKey(jsonBytes []byte, password string) (*keystore.Key, error)
Sign(digestHash []byte, prv *ecdsa.PrivateKey) ([]byte, error)
ReadFile(filename string) ([]byte, error)
}

type AccountUtils struct{}

//This function returns all the accounts in form of array
func (accountUtils AccountUtils) Accounts(path string) []accounts.Account {
ks := keystore.NewKeyStore(path, keystore.StandardScryptN, keystore.StandardScryptP)
return ks.Accounts()
}

//This function takes path and pass phrase as input and returns the new account
func (accountUtils AccountUtils) NewAccount(path string, passphrase string) (accounts.Account, error) {
ks := keystore.NewKeyStore(path, keystore.StandardScryptN, keystore.StandardScryptP)
accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, ks)
return ks.NewAccount(passphrase)
}

//This function takes json bytes array and password as input and returns the decrypted key
func (accountUtils AccountUtils) DecryptKey(jsonBytes []byte, password string) (*keystore.Key, error) {
return keystore.DecryptKey(jsonBytes, password)
type AccountManager struct {
Keystore *keystore.KeyStore
}

//This function takes hash in form of byte array and private key as input and returns signature as byte array
func (accountUtils AccountUtils) Sign(digestHash []byte, prv *ecdsa.PrivateKey) (sig []byte, err error) {
return crypto.Sign(digestHash, prv)
func NewAccountManager(keystorePath string) *AccountManager {
ks := keystore.NewKeyStore(keystorePath, keystore.StandardScryptN, keystore.StandardScryptP)
return &AccountManager{
Keystore: ks,
}
}

//This function takes name of the file as input and returns the file data as byte array
func (accountUtils AccountUtils) ReadFile(filename string) ([]byte, error) {
return os.ReadFile(filename)
// InitAccountStruct initializes an Account struct with provided details.
func InitAccountStruct(address, password string, accountManager types.AccountManagerInterface) types.Account {
return types.Account{
Address: address,
Password: password,
AccountManager: accountManager,
}
}
49 changes: 29 additions & 20 deletions accounts/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"crypto/ecdsa"
"errors"
"github.com/ethereum/go-ethereum/accounts"
"razor/core/types"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/crypto"
"os"
"razor/logger"
"razor/path"
"strings"
Expand All @@ -14,51 +16,58 @@ import (
var log = logger.NewLogger()

//This function takes path and password as input and returns new account
func (AccountUtils) CreateAccount(keystorePath string, password string) accounts.Account {
func (am *AccountManager) CreateAccount(keystorePath string, password string) accounts.Account {
if _, err := path.OSUtilsInterface.Stat(keystorePath); path.OSUtilsInterface.IsNotExist(err) {
mkdirErr := path.OSUtilsInterface.Mkdir(keystorePath, 0700)
if mkdirErr != nil {
log.Fatal("Error in creating directory: ", mkdirErr)
}
}
newAcc, err := AccountUtilsInterface.NewAccount(keystorePath, password)
newAcc, err := am.NewAccount(password)
if err != nil {
log.Fatal("Error in creating account: ", err)
}
return newAcc
}

//This function takes path and pass phrase as input and returns the new account
func (am *AccountManager) NewAccount(passphrase string) (accounts.Account, error) {
ks := am.Keystore
accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, ks)
return ks.NewAccount(passphrase)
}

//This function takes address of account, password and keystore path as input and returns private key of account
func (am *AccountManager) GetPrivateKey(address string, password string) (*ecdsa.PrivateKey, error) {
allAccounts := am.Keystore.Accounts()
for _, account := range allAccounts {
if strings.EqualFold(account.Address.Hex(), address) {
return getPrivateKeyFromKeystore(account.URL.Path, password)
}
}
return nil, errors.New("no keystore file found")
}

//This function takes and path of keystore and password as input and returns private key of account
func (AccountUtils) GetPrivateKeyFromKeystore(keystorePath string, password string) (*ecdsa.PrivateKey, error) {
jsonBytes, err := AccountUtilsInterface.ReadFile(keystorePath)
func getPrivateKeyFromKeystore(keystoreFilePath string, password string) (*ecdsa.PrivateKey, error) {
jsonBytes, err := os.ReadFile(keystoreFilePath)
if err != nil {
log.Error("Error in reading keystore: ", err)
return nil, err
}
key, err := AccountUtilsInterface.DecryptKey(jsonBytes, password)
key, err := keystore.DecryptKey(jsonBytes, password)
if err != nil {
log.Error("Error in fetching private key: ", err)
return nil, err
}
return key.PrivateKey, nil
}

//This function takes address of account, password and keystore path as input and returns private key of account
func (AccountUtils) GetPrivateKey(address string, password string, keystorePath string) (*ecdsa.PrivateKey, error) {
allAccounts := AccountUtilsInterface.Accounts(keystorePath)
for _, account := range allAccounts {
if strings.EqualFold(account.Address.Hex(), address) {
return AccountUtilsInterface.GetPrivateKeyFromKeystore(account.URL.Path, password)
}
}
return nil, errors.New("no keystore file found")
}

//This function takes hash, account and path as input and returns the signed data as array of byte
func (AccountUtils) SignData(hash []byte, account types.Account, defaultPath string) ([]byte, error) {
privateKey, err := AccountUtilsInterface.GetPrivateKey(account.Address, account.Password, defaultPath)
func (am *AccountManager) SignData(hash []byte, address string, password string) ([]byte, error) {
privateKey, err := am.GetPrivateKey(address, password)
if err != nil {
return nil, err
}
return AccountUtilsInterface.Sign(hash, privateKey)
return crypto.Sign(hash, privateKey)
}
Loading
Loading