@@ -67,6 +67,16 @@ func (arguments Arguments) LengthNonIndexed() int {
6767 return out
6868}
6969
70+ func (arguments Arguments ) NonIndexed () Arguments {
71+ var ret []Argument
72+ for _ ,arg := range arguments {
73+ if ! arg .Indexed {
74+ ret = append (ret , arg )
75+ }
76+ }
77+ return ret
78+ }
79+
7080// isTuple returns true for non-atomic constructs, like (uint,uint) or uint[]
7181func (arguments Arguments ) isTuple () bool {
7282 return len (arguments ) > 1
@@ -114,14 +124,9 @@ func (arguments Arguments) unpackTuple(v interface{}, output []byte) error {
114124 // `j` counts the number of complex types.
115125 // both `i` and `j` are used to to correctly compute `data` offset.
116126
117- i , j := - 1 , 0
118- for _ , arg := range arguments {
127+ j := 0
128+ for i , arg := range arguments . NonIndexed () {
119129
120- if arg .Indexed {
121- // can't read, continue
122- continue
123- }
124- i ++
125130 marshalledValue , err := toGoType ((i + j )* 32 , arg .Type , output )
126131 if err != nil {
127132 return err
@@ -178,15 +183,51 @@ func (arguments Arguments) unpackAtomic(v interface{}, output []byte) error {
178183 }
179184
180185 value := valueOf .Elem ()
181-
182186 marshalledValue , err := toGoType (0 , arg .Type , output )
183187 if err != nil {
184188 return err
185189 }
186190 return set (value , reflect .ValueOf (marshalledValue ), arg )
187191}
188192
189- // Unpack performs the operation Go format -> Hexdata
193+ // UnpackValues can be used to unpack ABI-encoded hexdata according to the ABI-specification,
194+ // without supplying a struct to unpack into. Instead, this method returns a list containing the
195+ // values. An atomic argument will be a list with one element.
196+ func (arguments Arguments ) UnpackValues (data []byte ) ([]interface {}, error ){
197+
198+ retval := make ([]interface {},0 ,arguments .LengthNonIndexed ())
199+
200+ virtualArgs := 0
201+
202+ for index ,arg := range arguments .NonIndexed (){
203+
204+ marshalledValue , err := toGoType ((index + virtualArgs ) * 32 , arg .Type , data )
205+
206+ if arg .Type .T == ArrayTy {
207+ //If we have a static array, like [3]uint256, these are coded as
208+ // just like uint256,uint256,uint256.
209+ // This means that we need to add two 'virtual' arguments when
210+ // we count the index from now on
211+
212+ virtualArgs += arg .Type .Size - 1
213+ }
214+
215+ if err != nil {
216+ return nil , err
217+ }
218+ retval = append (retval , marshalledValue )
219+ }
220+ return retval , nil
221+ }
222+
223+ // UnpackValues performs the operation Go format -> Hexdata
224+ // It is the semantic opposite of UnpackValues
225+ func (arguments Arguments ) PackValues (args []interface {}) ([]byte , error ) {
226+ return arguments .Pack (args ... )
227+ }
228+
229+
230+ // Pack performs the operation Go format -> Hexdata
190231func (arguments Arguments ) Pack (args ... interface {}) ([]byte , error ) {
191232 // Make sure arguments match up and pack them
192233 abiArgs := arguments
0 commit comments