-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorc721_pauseable.go
56 lines (48 loc) · 1.63 KB
/
orc721_pauseable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ethcli
import (
"context"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"math/big"
"strings"
)
var (
openzeppelinERC721PauseableAbi = `[{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"}]`
)
func (cli *ETHCli) ORC721Pause(token string, key string) (string, error) {
ins, err := abi.JSON(strings.NewReader(openzeppelinERC721PauseableAbi))
if err != nil {
return "", err
}
data, _ := ins.Pack("pause")
return cli.SendMondoTx(key, &token, "0", BytesToHex(data), "0", 0)
}
func (cli *ETHCli) ORC721Unpause(token string, key string) (string, error) {
ins, err := abi.JSON(strings.NewReader(openzeppelinERC721PauseableAbi))
if err != nil {
return "", err
}
data, _ := ins.Pack("unpause")
return cli.SendMondoTx(key, &token, "0", BytesToHex(data), "0", 0)
}
func (cli *ETHCli) ORC721Paused(token string, blockNumber *big.Int) (bool, error) {
ins, err := abi.JSON(strings.NewReader(openzeppelinERC721PauseableAbi))
if err != nil {
return false, err
}
data, _ := ins.Pack("paused")
contract := common.HexToAddress(token)
bz, err := cli.CallContract(context.Background(), ethereum.CallMsg{
To: &contract,
Data: data,
}, blockNumber)
if err != nil {
return false, err
}
results, err := ins.Unpack("paused", bz)
if err != nil {
return false, err
}
return results[0].(bool), nil
}