@@ -3,15 +3,13 @@ package ioid
3
3
import (
4
4
"bytes"
5
5
_ "embed" // used to embed contract abi
6
- "encoding/hex"
7
6
"fmt"
8
7
"math/big"
9
8
10
9
"github.com/ethereum/go-ethereum/accounts/abi"
11
10
"github.com/iotexproject/iotex-address/address"
12
11
"github.com/spf13/cobra"
13
12
14
- "github.com/iotexproject/iotex-core/ioctl/cmd/action"
15
13
"github.com/iotexproject/iotex-core/ioctl/config"
16
14
"github.com/iotexproject/iotex-core/ioctl/output"
17
15
)
@@ -67,81 +65,39 @@ func project() error {
67
65
return output .NewError (output .AddressError , "failed to convert ioIDStore address" , err )
68
66
}
69
67
70
- data , err := ioIDStoreABI . Pack ( "project" )
68
+ projectAddr , err := readContract ( ioioIDStore , ioIDStoreABI , "project" , "0 " )
71
69
if err != nil {
72
- return output .NewError (output .ConvertError , "failed to pack project arguments" , err )
73
- }
74
- res , err := action .Read (ioioIDStore , "0" , data )
75
- if err != nil {
76
- return output .NewError (output .APIError , "failed to read contract" , err )
77
- }
78
- data , _ = hex .DecodeString (res )
79
- projectAddr , err := ioIDStoreABI .Unpack ("project" , data )
80
- if err != nil {
81
- return output .NewError (output .ConvertError , "failed to unpack project response" , err )
70
+ return output .NewError (output .ConvertError , "failed to read project" , err )
82
71
}
83
72
84
73
ioProjectAddr , _ := address .FromHex (projectAddr [0 ].(address.Address ).String ())
85
- data , err = projectABI .Pack ("name" , new (big.Int ).SetUint64 (projectId ))
86
- if err != nil {
87
- return output .NewError (output .ConvertError , "failed to pack project name arguments" , err )
88
- }
89
- res , err = action .Read (ioProjectAddr , "0" , data )
90
- if err != nil {
91
- return output .NewError (output .APIError , "failed to read contract" , err )
92
- }
93
- data , _ = hex .DecodeString (res )
94
- name , err := projectABI .Unpack ("name" , data )
95
- if err != nil {
96
- return output .NewError (output .ConvertError , "failed to unpack project name response" , err )
97
- }
98
-
99
- data , err = ioIDStoreABI .Pack ("projectDeviceContract" , new (big.Int ).SetUint64 (projectId ))
100
- if err != nil {
101
- return output .NewError (output .ConvertError , "failed to pack project device contract arguments" , err )
102
- }
103
- res , err = action .Read (ioioIDStore , "0" , data )
104
- if err != nil {
105
- return output .NewError (output .APIError , "failed to read contract" , err )
106
- }
107
- data , _ = hex .DecodeString (res )
108
- deviceContractAddr , err := ioIDStoreABI .Unpack ("projectDeviceContract" , data )
109
- if err != nil {
110
- return output .NewError (output .ConvertError , "failed to unpack project device contract response" , err )
111
- }
112
-
113
- data , err = ioIDStoreABI .Pack ("projectAppliedAmount" , new (big.Int ).SetUint64 (projectId ))
114
- if err != nil {
115
- return output .NewError (output .ConvertError , "failed to pack project applied amount arguments" , err )
116
- }
117
- res , err = action .Read (ioioIDStore , "0" , data )
74
+ name , err := readContract (ioProjectAddr , projectABI , "name" , "0" , new (big.Int ).SetUint64 (projectId ))
118
75
if err != nil {
119
- return output .NewError (output .APIError , "failed to read contract " , err )
76
+ return output .NewError (output .ConvertError , "failed to read project name " , err )
120
77
}
121
- data , _ = hex .DecodeString (res )
122
- projectAppliedAmount , err := ioIDStoreABI .Unpack ("projectAppliedAmount" , data )
78
+ owner , err := readContract (ioProjectAddr , projectABI , "ownerOf" , "0" , new (big.Int ).SetUint64 (projectId ))
123
79
if err != nil {
124
- return output .NewError (output .ConvertError , "failed to unpack project applied amount response " , err )
80
+ return output .NewError (output .ConvertError , "failed to read project owner " , err )
125
81
}
126
82
127
- data , err = ioIDStoreABI . Pack ( "projectActivedAmount " , new (big.Int ).SetUint64 (projectId ))
83
+ deviceContractAddr , err := readContract ( ioioIDStore , ioIDStoreABI , "projectDeviceContract" , "0 " , new (big.Int ).SetUint64 (projectId ))
128
84
if err != nil {
129
- return output .NewError (output .ConvertError , "failed to pack project actived amount arguments " , err )
85
+ return output .NewError (output .ConvertError , "failed to read project device contract " , err )
130
86
}
131
- res , err = action . Read (ioioIDStore , " 0" , data )
87
+ projectAppliedAmount , err := readContract (ioioIDStore , ioIDStoreABI , "projectAppliedAmount" , " 0" , new (big. Int ). SetUint64 ( projectId ) )
132
88
if err != nil {
133
- return output .NewError (output .APIError , "failed to read contract " , err )
89
+ return output .NewError (output .ConvertError , "failed to read project device applied amount " , err )
134
90
}
135
- data , _ = hex .DecodeString (res )
136
- projectActivedAmount , err := ioIDStoreABI .Unpack ("projectActivedAmount" , data )
91
+ projectActivedAmount , err := readContract (ioioIDStore , ioIDStoreABI , "projectActivedAmount" , "0" , new (big.Int ).SetUint64 (projectId ))
137
92
if err != nil {
138
- return output .NewError (output .ConvertError , "failed to unpack project actived amount response " , err )
93
+ return output .NewError (output .ConvertError , "failed to read project actived amount" , err )
139
94
}
140
95
141
96
fmt .Printf (`Project #%d detail:
142
97
{
143
- "projectContractAddress ": "%s",
98
+ "projectContract ": "%s",
144
99
"name": "%s",
100
+ "owner": "%s",
145
101
"deviceNFT": "%s",
146
102
"appliedIoIDs": "%s",
147
103
"activedIoIDs": "%s",
@@ -150,6 +106,7 @@ func project() error {
150
106
projectId ,
151
107
projectAddr [0 ].(address.Address ).String (),
152
108
name [0 ].(string ),
109
+ owner [0 ].(address.Address ).String (),
153
110
deviceContractAddr [0 ].(address.Address ).String (),
154
111
projectAppliedAmount [0 ].(* big.Int ).String (),
155
112
projectActivedAmount [0 ].(* big.Int ).String (),
0 commit comments