OSDN Git Service

Fix list-assets vm_version field lost (#1705)
authoryahtoo <yahtoo.ma@gmail.com>
Wed, 17 Apr 2019 14:49:53 +0000 (22:49 +0800)
committerPaladz <yzhu101@uottawa.ca>
Wed, 17 Apr 2019 14:49:53 +0000 (22:49 +0800)
* Fix list-assets vm_version field lost

* Add err check

* Opz code

asset/annotate.go
blockchain/txbuilder/estimate.go
protocol/vm/vmutil/script.go
protocol/vm/vmutil/script_test.go

index 2c84852..52edf5c 100644 (file)
@@ -27,12 +27,13 @@ func Annotated(a *Asset) (*query.AnnotatedAsset, error) {
        annotatedAsset := &query.AnnotatedAsset{
                ID:                a.AssetID,
                Alias:             *a.Alias,
+               VMVersion:         a.VMVersion,
                RawDefinitionByte: a.RawDefinitionByte,
                Definition:        &jsonDefinition,
                IssuanceProgram:   chainjson.HexBytes(a.IssuanceProgram),
        }
 
-       annotatedAsset.LimitHeight, _ = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
+       annotatedAsset.LimitHeight = vmutil.GetIssuanceProgramRestrictHeight(a.IssuanceProgram)
        if a.Signer != nil {
                annotatedAsset.AnnotatedSigner = query.AnnotatedSigner{
                        Type:       a.Signer.Type,
index 0f48679..27497eb 100644 (file)
@@ -36,7 +36,7 @@ func EstimateTxGas(template Template) (*EstimateTxGasInfo, error) {
 
                case types.IssuanceInputType:
                        issuanceProgram := input.IssuanceProgram()
-                       if height, _ := vmutil.GetIssuanceProgramRestrictHeight(issuanceProgram); height > 0 {
+                       if height := vmutil.GetIssuanceProgramRestrictHeight(issuanceProgram); height > 0 {
                                // the gas for issue program with checking block height
                                totalIssueGas += 5
                        }
index 1f0d82f..7cef891 100644 (file)
@@ -135,14 +135,20 @@ func checkMultiSigParams(nrequired, npubkeys int64) error {
 }
 
 // GetIssuanceProgramRestrictHeight return issuance program restrict height
-func GetIssuanceProgramRestrictHeight(program []byte) (int64, error) {
+// if height invalid return 0
+func GetIssuanceProgramRestrictHeight(program []byte) int64 {
        insts, err := vm.ParseProgram(program)
        if err != nil {
-               return 0, err
+               return 0
        }
 
        if len(insts) >= 4 && insts[0].IsPushdata() && insts[1].Op == vm.OP_BLOCKHEIGHT && insts[2].Op == vm.OP_GREATERTHAN && insts[3].Op == vm.OP_VERIFY {
-               return vm.AsInt64(insts[0].Data)
+               height, err := vm.AsInt64(insts[0].Data)
+               if err != nil {
+                       return 0
+               }
+
+               return height
        }
-       return 0, nil
+       return 0
 }
index 3e0d211..b5c2b63 100644 (file)
@@ -214,7 +214,7 @@ func TestGetIssuanceProgramRestrictHeight(t *testing.T) {
                        t.Fatal(err)
                }
 
-               gotHeight, _ := GetIssuanceProgramRestrictHeight(program)
+               gotHeight := GetIssuanceProgramRestrictHeight(program)
                if gotHeight != test.wantHeight {
                        t.Errorf("TestGetIssuanceProgramRestrictHeight #%d failed: got %d want %d", i, gotHeight, test.wantHeight)
                }