Skip to content

Commit

Permalink
add replenish contract (#109)
Browse files Browse the repository at this point in the history
* add replenish contract

* go fmt

* change param to list

Co-authored-by: zhang menghang <[email protected]>
  • Loading branch information
siovanus and zhang menghang authored Jan 25, 2022
1 parent f584142 commit fd12488
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
52 changes: 52 additions & 0 deletions native/service/governance/replenish/param.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2021 The poly network Authors
* This file is part of The poly network library.
*
* The poly network is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The poly network is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with The poly network . If not, see <http://www.gnu.org/licenses/>.
*/

package replenish

import (
"fmt"
"github.com/polynetwork/poly/common"
)

type ReplenishTxParam struct {
TxHashes []string
}

func (this *ReplenishTxParam) Serialization(sink *common.ZeroCopySink) {
sink.WriteVarUint(uint64(len(this.TxHashes)))
for _, v := range this.TxHashes {
sink.WriteString(v)
}
}

func (this *ReplenishTxParam) Deserialization(source *common.ZeroCopySource) error {
n, eof := source.NextVarUint()
if eof {
return fmt.Errorf("source.NextVarUint, deserialize txhashes length error")
}
txHashes := make([]string, 0)
for i := 0; uint64(i) < n; i++ {
txHash, eof := source.NextString()
if eof {
return fmt.Errorf("source.NextString, deserialize tx hash error")
}
txHashes = append(txHashes, txHash)
}

this.TxHashes = txHashes
return nil
}
51 changes: 51 additions & 0 deletions native/service/governance/replenish/replenish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (C) 2021 The poly network Authors
* This file is part of The poly network library.
*
* The poly network is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The poly network is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License
* along with The poly network . If not, see <http://www.gnu.org/licenses/>.
*/

package replenish

import (
"fmt"
"github.com/polynetwork/poly/native/event"

"github.com/polynetwork/poly/common"
"github.com/polynetwork/poly/native"
"github.com/polynetwork/poly/native/service/utils"
)

const (
//function name
REPLENISH_TX = "replenishTx"
)

//Register methods
func RegisterReplenishContract(native *native.NativeService) {
native.Register(REPLENISH_TX, ReplenishTx)
}

func ReplenishTx(native *native.NativeService) ([]byte, error) {
params := new(ReplenishTxParam)
if err := params.Deserialization(common.NewZeroCopySource(native.GetInput())); err != nil {
return utils.BYTE_FALSE, fmt.Errorf("ReplenishTx, contract params deserialize error: %v", err)
}

native.AddNotify(
&event.NotifyEventInfo{
ContractAddress: utils.ReplenishContractAddress,
States: []interface{}{"ReplenishTx", params.TxHashes},
})
return utils.BYTE_TRUE, nil
}
2 changes: 2 additions & 0 deletions native/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/polynetwork/poly/native/service/governance/neo3_state_manager"
"github.com/polynetwork/poly/native/service/governance/node_manager"
"github.com/polynetwork/poly/native/service/governance/relayer_manager"
"github.com/polynetwork/poly/native/service/governance/replenish"
"github.com/polynetwork/poly/native/service/governance/side_chain_manager"
"github.com/polynetwork/poly/native/service/header_sync"
"github.com/polynetwork/poly/native/service/utils"
Expand All @@ -36,6 +37,7 @@ func init() {
native.Contracts[utils.NodeManagerContractAddress] = node_manager.RegisterNodeManagerContract
native.Contracts[utils.RelayerManagerContractAddress] = relayer_manager.RegisterRelayerManagerContract
native.Contracts[utils.Neo3StateManagerContractAddress] = neo3_state_manager.RegisterStateValidatorManagerContract
native.Contracts[utils.ReplenishContractAddress] = replenish.RegisterReplenishContract

config.EXTRA_INFO_HEIGHT_FORK_CHECK = true
}
1 change: 1 addition & 0 deletions native/service/utils/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var (
NodeManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05})
RelayerManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06})
Neo3StateManagerContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07})
ReplenishContractAddress, _ = common.AddressParseFromBytes([]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08})

VOTE_ROUTER = uint64(0)
BTC_ROUTER = uint64(1)
Expand Down

0 comments on commit fd12488

Please sign in to comment.