Skip to content

Commit

Permalink
code cleanup with gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mocacinno committed Mar 6, 2024
1 parent 36cdd76 commit f3fbde1
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
14 changes: 7 additions & 7 deletions blocks/blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func CreateNewBlock(blocknumber int, userStruct []shared.Identity) []shared.Iden
randomNumber := rand.Intn(5) + 1
lijnnumber := 1
for transaction := 1; transaction <= randomNumber; transaction++ {
UpdateduserStruct, txline := CreateNewTransaction(userStruct,blocknumber,lijnnumber)
lijnnumber = lijnnumber +1
UpdateduserStruct, txline := CreateNewTransaction(userStruct, blocknumber, lijnnumber)
lijnnumber = lijnnumber + 1
userStruct = UpdateduserStruct
if err := csvwriter.Write(txline); err != nil {
log.Fatalln("error writing record to file", err)
Expand Down Expand Up @@ -108,7 +108,7 @@ func CreateNewTransaction(userStruct []shared.Identity, newblock_number int, new

UpdateduserStruct, value, blocknumber, linenumber, sender := UpdateUserRemoveUnspentoutputs(selectedEntry.Id, randomIndexUnspentOutput, userStruct)
if shared.Myparameters.Debug {
fmt.Printf("going to use unspent output of block %d, line %d with value %d from sender %s\n\n", blocknumber, linenumber, value, sender)
fmt.Printf("going to use unspent output of block %d, line %d with value %d from sender %s\n\n", blocknumber, linenumber, value, sender)
}
userStruct = UpdateduserStruct
if shared.Myparameters.Verbose {
Expand Down Expand Up @@ -179,7 +179,7 @@ func CreateNewTransaction(userStruct []shared.Identity, newblock_number int, new
fmt.Printf("as output, created tx csv line: %+v\n", outputline)
}
if shared.Myparameters.Debug || shared.Myparameters.Verbose {
fmt.Printf("debug: tosign: '%s'\n, signer: '%s'\n, signature: '%s'\n\n\n", tosign, sender, signature)
fmt.Printf("debug: tosign: '%s'\n, signer: '%s'\n, signature: '%s'\n\n\n", tosign, sender, signature)
}
outputline = append(outputline, signature)
return userStruct, outputline
Expand All @@ -192,8 +192,8 @@ func UpdateUserRemoveUnspentoutputs(IdentityIndex int, UnspentOutputIndex int, i
linenumber := unspentoutputslice[UnspentOutputIndex].Linenumber
sender := identities[IdentityIndex].Name
/*
jstruct, _ := json.MarshalIndent(identities[IdentityIndex], "", "\t")
fmt.Printf("the unspent outputslice %s\n", jstruct)
jstruct, _ := json.MarshalIndent(identities[IdentityIndex], "", "\t")
fmt.Printf("the unspent outputslice %s\n", jstruct)
*/
if IdentityIndex < 0 || IdentityIndex >= len(identities) {
fmt.Println("Invalid IdentityIndex")
Expand All @@ -215,7 +215,7 @@ func UpdateUserRemoveUnspentoutputs(IdentityIndex int, UnspentOutputIndex int, i

func UpdateUserAddUnspentoutputs(indexnumber int, blocknumber int, linenumber int, value int, identities []shared.Identity) []shared.Identity {
if shared.Myparameters.Debug {
fmt.Printf("adding new unspent output to user with index %d, coming from blocknumber %d, linunumber %d and value %d\n", indexnumber, blocknumber, linenumber, value)
fmt.Printf("adding new unspent output to user with index %d, coming from blocknumber %d, linunumber %d and value %d\n", indexnumber, blocknumber, linenumber, value)
}
updateslice := identities[indexnumber]
Unspentoutputslice := updateslice.Unspentoutputs
Expand Down
2 changes: 1 addition & 1 deletion files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ func CreateDirs() error {
}

return nil
}
}
3 changes: 2 additions & 1 deletion identity/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/pem"
"os"
)

/*
func GenerateIdentity(name string) *shared.Identity {
privKey, _ := rsa.GenerateKey(rand.Reader, 2048)
Expand All @@ -25,7 +26,7 @@ func GenerateIdentity(name string) (*shared.Identity, error) {
}

// Save private key to file
privKeyFile, err := os.Create("output/keys/" +name + "_private.pem")
privKeyFile, err := os.Create("output/keys/" + name + "_private.pem")
if err != nil {
return nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"strings"
)


func main() {
flags.ParseFlags()
files.CreateDirs()
Expand All @@ -22,7 +21,6 @@ func main() {
userStruct = append(userStruct, newidentity)
}


unspentoutputsvalue := blocks.CreateInitialBlock(userStruct[0], shared.Myparameters.InputValue)
userStruct = blocks.UpdateUserAddUnspentoutputs(0, 0, 1, unspentoutputsvalue, userStruct)
for blocknumber := 2; blocknumber <= shared.Myparameters.NumberOfBlocks; blocknumber++ {
Expand Down
5 changes: 3 additions & 2 deletions shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Parameters struct {
Namelist string
InputValue int
NumberOfBlocks int
Debug bool
Debug bool
}

var Myparameters Parameters
Expand All @@ -21,10 +21,11 @@ type Identity struct {
Unspentoutputs []UnspentOutput
Id int
}

/*
type Identity struct {
Name string
PublicKey *rsa.PublicKey
PublicKey *rsa.PublicKey
PrivateKey *rsa.PrivateKey
Unspentoutputs []UnspentOutput
Id int
Expand Down
12 changes: 6 additions & 6 deletions signing/signing.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func SignMessage(privateKey *rsa.PrivateKey, message string) (string, error) {
*/

func SignMessage(privateKey *rsa.PrivateKey, message string) (string, error) {
hashed := sha256.Sum256([]byte(message))
signature, err := rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA256, hashed[:])
if err != nil {
return "", err
}
return fmt.Sprintf("%x", signature), nil
hashed := sha256.Sum256([]byte(message))
signature, err := rsa.SignPKCS1v15(rand.Reader, privateKey, crypto.SHA256, hashed[:])
if err != nil {
return "", err
}
return fmt.Sprintf("%x", signature), nil
}

func ValidateSignature(publicKey *rsa.PublicKey, message, signature string) bool {
Expand Down

0 comments on commit f3fbde1

Please sign in to comment.