Skip to content

Commit 812475c

Browse files
zhangbinttblack
authored andcommitted
fixed getMainChainLatestHeight bug
1 parent 09a73eb commit 812475c

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

core/vm/contracts.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ func (c *getMainChainBlockByHeight) Run(input []byte) ([]byte, error) {
14231423

14241424
header, err := spv.SpvService.GetELAHeader(uint32(height.Uint64()))
14251425
if err != nil {
1426-
log.Error("getMainChainBlockHeight failed", "error", err, " height", height)
1426+
log.Error("getMainChainBlockByHeight failed", "error", err, " height", height)
14271427
return []byte{}, err
14281428
}
14291429

@@ -1450,10 +1450,9 @@ func (c *getMainChainBlockByHeight) Run(input []byte) ([]byte, error) {
14501450
m := abi.Method{Inputs: arguments}
14511451
ret, err := m.Inputs.Pack(header.Previous(), header.Bits(), header.MerkleRoot(), header.Hash(), header.Height)
14521452
if err != nil {
1453-
log.Error("getMainChainBlockHeight failed ", "error ", err)
1453+
log.Error("getMainChainBlockByHeight failed ", "error ", err)
14541454
return ret, err
14551455
}
1456-
fmt.Println("getMainChainBlockHeight success", ret, "len ", len(ret))
14571456
return ret, nil
14581457
}
14591458

@@ -1469,6 +1468,17 @@ func (h *getMainChainLatestHeight) Run(input []byte) ([]byte, error) {
14691468
log.Error("getMainChainLatestHeight failed", "error", err)
14701469
return []byte{}, err
14711470
}
1472-
height := big.NewInt(0).SetUint64(uint64(head.Height))
1473-
return height.Bytes(), nil
1471+
UInt32, _ := abi.NewType("uint32", "uint32", nil)
1472+
arguments := make([]abi.Argument, 0)
1473+
1474+
Height := abi.Argument{Name: "Height", Type: UInt32}
1475+
arguments = append(arguments, Height)
1476+
1477+
m := abi.Method{Inputs: arguments}
1478+
ret, err := m.Inputs.Pack(head.Height)
1479+
if err != nil {
1480+
log.Error("getMainChainLatestHeight pack failed ", "error ", err)
1481+
return ret, err
1482+
}
1483+
return ret, nil
14741484
}

0 commit comments

Comments
 (0)