Skip to content
Open
Changes from 1 commit
Commits
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
30 changes: 4 additions & 26 deletions internal/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,41 +278,20 @@ func (mc *JSONContract) Unmarshal() (Contract, error) {
fmt.print(c)
Copy link
Member

@kastolars kastolars Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • remove print call here

}

func (c *Contract) ContainsPublicKey(pk publickey.AurumPublicKey) (bool, error) {
if c == nil {
return false, errors.New("not nill")
}

// encode contract's sender pub key to bytes
bKey, err := publickey.Encode(c.SenderPubKey)
if err != nil{
return bytes.Equal(bKey, pk.Bytes), errors.New("failed to encode sender public key")
}
// return the comparison of the above encoding with Bytes field of pk
return bytes.Equal(bKey, pk.Bytes), nil

}

func(c *Contract) GenerateRandomContract() (Contract){

funcGenerateRandomContract() Contract{
b := rand.Read(make([]byte, 32))

genSenderPubKey := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ecdsa.GenerateKey generates a private key. You need to extract the public key from the private key

How this is done: https://github.com/SIGBlockchain/project_aurum/blob/master/internal/publickey/publickey_test.go#L56


genrecipPubKeyHash := rand.Read(make([]byte, 32))
Copy link
Member

@kastolars kastolars Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Fix camelCase format


genVersion := binary.LittleEndian.Uint16(b[:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make sure this is never 0? The only instance New returns an error is if the version passed in is a zero.

  • Generate only nonzero numbers for version
  • Make return type be just a Contract

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new function returns 2 values, contract and error, so when I return a new *random contract, it also returns error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. We can do what you had initially: define a return variable, with its error, then just return the return variable at the end. It doesn't make much sense to generate a random contract and need to do error checks on the call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the new function already checks if the version is greater than 0. do u want it so that is doesn't make a contract with a zero value version in the first place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is exactly what I want.


genSigLen := binary.LittleEndian.Uint8(b[:]);


genSignature := rand.Read(make([]byte, genSigLen));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove these two Sig variables, since we don't need them in the New function


genValue := binary.LittleEndian.Uint64(b[:])

genStateNonce := binary.LittleEndian.Uint64(b[:])


c := &Contract{
return &Contract{
Version: genVersion,
SenderPubKey: genSenderPubKey,
SigLen: genSigLen,
Expand All @@ -321,7 +300,6 @@ func(c *Contract) GenerateRandomContract() (Contract){
Value: genValue,
StateNonce: genStateNonce,

}
return c, nil
}, nil
Copy link
Member

@kastolars kastolars Oct 30, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • There is no need to return a nil here, since your function only returns a Contract per the signature.


}