-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from 42School/dev/go/eth
[Version]: v2 - beta
- Loading branch information
Showing
18 changed files
with
429 additions
and
110 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
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
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
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,4 @@ | ||
#file name, password | ||
UTC--2020-07-24T08-19-17.983576000Z--cac03bac6965e6d8ca96537a0344cc506b32c2c7, password | ||
UTC--2020-07-24T08-24-31.985849000Z--fe5ac6a7bb66da6916becb74a4a3e00074cd2599, password | ||
UTC--2020-07-24T08-25-31.194883000Z--aec7bdfb241e56c04acf5e1a2a49f147867b85b7, password |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
keystore/UTC--2020-07-24T08-19-17.983576000Z--cac03bac6965e6d8ca96537a0344cc506b32c2c7
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 @@ | ||
{"address":"cac03bac6965e6d8ca96537a0344cc506b32c2c7","crypto":{"cipher":"aes-128-ctr","ciphertext":"b0f7933ddae70555ec5e9be4eeaf69bf54b97af2339cb31c7ea8b84906ad6ca7","cipherparams":{"iv":"ebfb836718296ff3b9659500d17e5b69"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"def9f196f7f993e06b9cbf51c2c851f179d662598fad54e28689aebc844d0042"},"mac":"d7ad37f3eb085a20ce9e63f6a60c3074c7868c1d21fe903ac255fffc235fc6a1"},"id":"1264d556-0a3a-4500-b0bd-1caf4b52ae8d","version":3} |
1 change: 1 addition & 0 deletions
1
keystore/UTC--2020-07-24T08-24-31.985849000Z--fe5ac6a7bb66da6916becb74a4a3e00074cd2599
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 @@ | ||
{"address":"fe5ac6a7bb66da6916becb74a4a3e00074cd2599","crypto":{"cipher":"aes-128-ctr","ciphertext":"63e3dcea141801c206eb576eff5447ef73d66b918887d3a15e876eb5de8b435d","cipherparams":{"iv":"e4f94f97b28d2fde10a50d46456c13cf"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"9670a93a59bf542a3cdc2719a68c7fb48e07f4e90d6bcb9a4187889e9230bc8a"},"mac":"f9ab926a2097eb2b13afc8bb9cc796909900c2da33e487c110a770af0094e37b"},"id":"cefadaf8-d5d4-4613-a299-09c263f4e3f6","version":3} |
1 change: 1 addition & 0 deletions
1
keystore/UTC--2020-07-24T08-25-31.194883000Z--aec7bdfb241e56c04acf5e1a2a49f147867b85b7
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 @@ | ||
{"address":"aec7bdfb241e56c04acf5e1a2a49f147867b85b7","crypto":{"cipher":"aes-128-ctr","ciphertext":"0adfabd931884c06624972f353d76d555a57e234df3e292cb725de7a1cebad60","cipherparams":{"iv":"7688c51e8e753e55e21557b7deb80370"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"ac0947910cfd927c15072225ab6e3d91d4b89c34144384081e1b742b535d2153"},"mac":"8491060883404e8fc9dd6d7c12761fe6eb6a69c85b6928e2a684baa35025a170"},"id":"5bfeda77-4edb-4c3c-9329-ffa8eadf7d8c","version":3} |
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
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 |
---|---|---|
@@ -1,36 +1,73 @@ | ||
package account | ||
|
||
import ( | ||
"fmt" | ||
"crypto/ecdsa" | ||
"github.com/42School/blockchain-service/src/global" | ||
"github.com/42School/blockchain-service/src/tools" | ||
"github.com/ethereum/go-ethereum/accounts" | ||
"github.com/ethereum/go-ethereum/accounts/keystore" | ||
"github.com/42School/blockchain-service/src/global" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/common/hexutil" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
"io/ioutil" | ||
"log" | ||
"strings" | ||
) | ||
|
||
var AccountsManager *accounts.Manager | ||
type Account struct { | ||
KeyStoreFile string | ||
Password string | ||
} | ||
|
||
var KeyStore *keystore.KeyStore | ||
var CurrentAccount int = 0 | ||
var Accounts []Account | ||
|
||
func ParseAccounts() { | ||
bits, err := ioutil.ReadFile("./accounts.csv") | ||
if err == nil { | ||
data := string(bits) | ||
lines := strings.Split(data, "\n") | ||
for i := 0; i < len(lines); i++ { | ||
line := lines[i] | ||
if line[0] != '#' { | ||
accountData := strings.Split(line, ", ") | ||
account := Account{accountData[0], accountData[1]} | ||
Accounts = append(Accounts, account) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func CreateAccountsManager() { | ||
KeyStore = keystore.NewKeyStore(global.PathKeyStore, keystore.StandardScryptN, keystore.StandardScryptP) | ||
AccountsManager = accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: false}, KeyStore) | ||
KeyStore = keystore.NewKeyStore(global.PathKeyStoreSign, keystore.StandardScryptN, keystore.StandardScryptP) | ||
ParseAccounts() | ||
} | ||
|
||
func GetAccount() accounts.Account { | ||
func GetSignAccount() accounts.Account { | ||
return KeyStore.Accounts()[0] | ||
} | ||
|
||
func GetKey() (*keystore.Key, error) { | ||
keyjson, errRead := ioutil.ReadFile(global.PathKeyStore + "/" + global.FileKeyStore) | ||
func GetWriterAccount() (common.Address, *ecdsa.PrivateKey, error) { | ||
keyjson, errRead := ioutil.ReadFile(global.PathKeyStore + "/" + Accounts[CurrentAccount].KeyStoreFile) | ||
if errRead != nil { | ||
return nil, errRead | ||
return common.Address{}, nil, errRead | ||
} | ||
key, errDecrypt := keystore.DecryptKey(keyjson, global.PasswordAccount) | ||
key, errDecrypt := keystore.DecryptKey(keyjson, Accounts[CurrentAccount].Password) | ||
if errDecrypt != nil { | ||
return nil, errDecrypt | ||
return common.Address{}, nil, errDecrypt | ||
} | ||
if key.Address != global.OfficialAddress { | ||
return nil, fmt.Errorf("key content mismatch: have account %x, want %x", key.Address, global.OfficialAddress) | ||
log.Println("pk:", hexutil.Encode(crypto.FromECDSA(key.PrivateKey))) | ||
return key.Address, key.PrivateKey, nil | ||
} | ||
|
||
func ChangeAccount() { | ||
// Send Mail of Current Account | ||
address, _, _ := GetWriterAccount() | ||
tools.SendMail("Empty Account", address.Hex()) | ||
if CurrentAccount + 1 == len(Accounts) { | ||
CurrentAccount = 0 | ||
} else { | ||
CurrentAccount = CurrentAccount + 1 | ||
} | ||
return key, nil | ||
} |
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
Oops, something went wrong.