-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add replenish contract * go fmt * change param to list Co-authored-by: zhang menghang <[email protected]>
- Loading branch information
Showing
4 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters