@@ -40,6 +40,24 @@ const sanitizedValue = dirtyValueArray => {
4040 return sanitizedValueArray ;
4141} ;
4242
43+ // filter `signature` property from an event
44+ const sanitizeEvent = dirtyEvent =>
45+ Object . entries ( dirtyEvent ) . reduce (
46+ ( acc , [ property , value ] ) =>
47+ property === "signature"
48+ ? acc
49+ : Object . assign ( acc , { [ property ] : value } ) ,
50+ { }
51+ ) ;
52+
53+ // sanitize aggregrate events given a `network-object.spec.json#events` object
54+ const sanitizeAllEvents = dirtyEvents =>
55+ Object . entries ( dirtyEvents ) . reduce (
56+ ( acc , [ property , event ] ) =>
57+ Object . assign ( acc , { [ property ] : sanitizeEvent ( event ) } ) ,
58+ { }
59+ ) ;
60+
4361var properties = {
4462 contractName : {
4563 sources : [ "contractName" , "contract_name" ]
@@ -112,14 +130,32 @@ var properties = {
112130 } ,
113131 compiler : { } ,
114132 networks : {
115- transform : function ( value , obj ) {
116- if ( value === undefined ) {
117- value = { } ;
118- }
119- if ( obj . network_id && value [ obj . network_id ] ) {
120- value [ obj . network_id ] . events = obj . events ;
121- value [ obj . network_id ] . links = obj . links ;
133+ /**
134+ * Normalize a networks object. Currently this makes sure `events` are
135+ * always sanitized and `links` is extracted when copying from
136+ * a TruffleContract context object.
137+ *
138+ * @param {object } value - the target object
139+ * @param {object | TruffleContract } obj - the context, or source object.
140+ * @return {object } The normalized Network object
141+ */
142+ transform : function ( value = { } , obj ) {
143+ // Sanitize value's events for known networks
144+ Object . keys ( value ) . forEach ( networkId => {
145+ if ( value [ networkId ] . events ) {
146+ value [ networkId ] . events = sanitizeAllEvents ( value [ networkId ] . events ) ;
147+ }
148+ } ) ;
149+
150+ // Set and sanitize the current networks property from the
151+ // TruffleContract. Note: obj is a TruffleContract if it has
152+ // `network_id` attribute
153+ const networkId = obj . network_id ;
154+ if ( networkId && value . hasOwnProperty ( networkId ) ) {
155+ value [ networkId ] . links = obj . links ;
156+ value [ networkId ] . events = sanitizeAllEvents ( obj . events ) ;
122157 }
158+
123159 return value ;
124160 }
125161 } ,
0 commit comments