-
Notifications
You must be signed in to change notification settings - Fork 0
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
added generaterandomcontract function #426
base: dev
Are you sure you want to change the base?
Changes from 16 commits
e2284d2
8ed5ff7
171ed51
308d102
7be827d
098b25d
071041b
dd1f0eb
2d3ded8
66438e7
8ba2b33
91fd671
545e1f3
fec9d8a
7f88d5c
f662f84
a6eb843
a2c1d66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,15 @@ package contracts | |
import ( | ||
"bytes" | ||
"crypto/ecdsa" | ||
"crypto/rand" | ||
crand "crypto/rand" | ||
mrand "math/rand" | ||
"encoding/binary" | ||
"encoding/hex" | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
|
||
|
||
|
||
"github.com/SIGBlockchain/project_aurum/internal/hashing" | ||
"github.com/SIGBlockchain/project_aurum/internal/publickey" | ||
) | ||
|
@@ -55,7 +57,7 @@ func New(version uint16, sender *ecdsa.PrivateKey, recipient []byte, value uint6 | |
|
||
if version == 0 { | ||
return nil, errors.New("Invalid version; must be >= 1") | ||
} | ||
} | ||
|
||
c := Contract{ | ||
Version: version, | ||
|
@@ -174,7 +176,7 @@ func (c *Contract) Sign(sender *ecdsa.PrivateKey) error { | |
return errors.New("Failed to serialize contract") | ||
} | ||
hashedContract := hashing.New(serializedTestContract) | ||
c.Signature, _ = sender.Sign(rand.Reader, hashedContract, nil) | ||
c.Signature, _ = sender.Sign(crand.Reader, hashedContract, nil) | ||
c.SigLen = uint8(len(c.Signature)) | ||
return nil | ||
} | ||
|
@@ -273,5 +275,30 @@ func (mc *JSONContract) Unmarshal() (Contract, error) { | |
mc.Value, | ||
mc.StateNonce, | ||
} | ||
return c, nil | ||
return c, nil | ||
|
||
} | ||
|
||
|
||
|
||
func GenerateRandomContract() (*Contract){ | ||
min := 1 | ||
maxVer := 65535 | ||
b := make([]byte, 32) | ||
mrand.Read(b) | ||
genRecipPubKeyHash := b | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you make this the result of the hash of a random number? i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does it matter how long the number inside the byte is, as in does it matter if it is a random Uint16 or Uint64 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought an array of bytes was multiple values, not just one singular number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think it matters. Choose whichever is easier for you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to have an array of bytes with just a single number There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i thought it was an array with multiple numbers |
||
genVersion := mrand.Intn(maxVer - min) + min | ||
genValue := mrand.Uint64()+uint64(min) | ||
genStateNonce := mrand.Uint64()+uint64(min) | ||
|
||
c:= &Contract{ | ||
RecipPubKeyHash: genRecipPubKeyHash, | ||
Version: uint16(genVersion), | ||
Value: genValue, | ||
StateNonce: genStateNonce, | ||
} | ||
return c | ||
} | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this?