Skip to content
Merged
Changes from all commits
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
20 changes: 9 additions & 11 deletions pkg/proto/transactions_with_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
maxArguments = 22
maxFunctionNameBytes = 255
maxInvokeScriptWithProofsBytes = 5 * 1024

topRideVersion = 5
)

// IssueWithProofs is a transaction to issue new asset, second version.
Expand Down Expand Up @@ -184,9 +186,8 @@ func validContentType(t byte) bool {
return t >= 1 && t <= 3
}

// version in range [0, 5)
func validStdVersion(v byte) bool {
return v < 5
func validScriptVersion(v byte) bool {
return v <= topRideVersion
}

func (tx *IssueWithProofs) Validate() (Transaction, error) {
Expand All @@ -198,23 +199,20 @@ func (tx *IssueWithProofs) Validate() (Transaction, error) {
return tx, err
}
if tx.NonEmptyScript() {
if !validStdVersion(tx.Script[0]) {
if !validScriptVersion(tx.Script[0]) {
return tx, errors.Errorf("Invalid version of script: %d", tx.Script[0])
}

if tx.Script[0] == 0 { // version byte
if len(tx.Script) <= 2 {
return tx, errors.Errorf("Illegal length of script: %d", len(tx.Script))
}
if !validContentType(tx.Script[1]) {
return tx, errors.Errorf("Invalid content type of script: %d", tx.Script[1])
}
if tx.Script[2] > 4 { // 4 is current max script version
if !validScriptVersion(tx.Script[2]) {
return tx, errors.Errorf("Invalid version of script: %d", tx.Script[2])
}

}

if !tx.Script.IsValidChecksum() {
return tx, errors.Errorf("Invalid checksum: %+v", []byte(tx.Script))
}
Expand Down Expand Up @@ -3152,7 +3150,7 @@ func (tx *DataWithProofs) bodyUnmarshalBinary(data []byte) error {
if err != nil {
return errors.Errorf("failed to extract type of data entry")
}
switch DataValueType(t) {
switch t {
case DataInteger:
var ie IntegerDataEntry
err = ie.UnmarshalBinary(data)
Expand Down Expand Up @@ -4281,7 +4279,7 @@ func (tx *InvokeScriptWithProofs) Clone() *InvokeScriptWithProofs {
return out
}

//NewUnsignedSetAssetScriptWithProofs creates new unsigned SetAssetScriptWithProofs transaction.
//NewUnsignedInvokeScriptWithProofs creates new unsigned InvokeScriptWithProofs transaction.
func NewUnsignedInvokeScriptWithProofs(v, chain byte, senderPK crypto.PublicKey, scriptRecipient Recipient, call FunctionCall, payments ScriptPayments, feeAsset OptionalAsset, fee, timestamp uint64) *InvokeScriptWithProofs {
return &InvokeScriptWithProofs{
Type: InvokeScriptTransaction,
Expand Down Expand Up @@ -4756,7 +4754,7 @@ func (tx *UpdateAssetInfoWithProofs) MarshalBinary() ([]byte, error) {
return nil, errors.New("binary format is not defined for UpdateAssetInfoTransaction")
}

func (tx *UpdateAssetInfoWithProofs) UnmarshalBinary(data []byte, scheme Scheme) error {
func (tx *UpdateAssetInfoWithProofs) UnmarshalBinary(_ []byte, _ Scheme) error {
return errors.New("binary format is not defined for UpdateAssetInfoTransaction")
}

Expand Down