@@ -7,6 +7,7 @@ const ChainUtil = require('../chain-util');
77const Transaction = require ( '../tx-pool/transaction' ) ;
88const StateNode = require ( './state-node' ) ;
99const {
10+ isValidPathForStates,
1011 isValidJsObjectForStates,
1112 jsObjectToStateTree,
1213 stateTreeToJsObject,
@@ -218,11 +219,15 @@ class DB {
218219 // TODO(seo): Consider making set operation and native function run tightly bound, i.e., revert
219220 // the former if the latter fails.
220221 setValue ( valuePath , value , address , timestamp , transaction ) {
221- const { isValid , invalidPath } = isValidJsObjectForStates ( value ) ;
222- if ( ! isValid ) {
223- return { code : 6 , error_message : `Invalid object for states: ${ invalidPath } ` } ;
222+ const isValidObj = isValidJsObjectForStates ( value ) ;
223+ if ( ! isValidObj . isValid ) {
224+ return { code : 6 , error_message : `Invalid object for states: ${ isValidObj . invalidPath } ` } ;
224225 }
225226 const parsedPath = ChainUtil . parsePath ( valuePath ) ;
227+ const isValidPath = isValidPathForStates ( parsedPath ) ;
228+ if ( ! isValidPath . isValid ) {
229+ return { code : 7 , error_message : `Invalid path: ${ isValidPath . invalidPath } ` } ;
230+ }
226231 if ( ! this . getPermissionForValue ( parsedPath , value , address , timestamp ) ) {
227232 return { code : 2 , error_message : `No .write permission on: ${ valuePath } ` } ;
228233 }
@@ -258,11 +263,15 @@ class DB {
258263 }
259264
260265 setFunction ( functionPath , functionInfo , address ) {
261- const { isValid , invalidPath } = isValidJsObjectForStates ( functionInfo ) ;
262- if ( ! isValid ) {
263- return { code : 6 , error_message : `Invalid object for states: ${ invalidPath } ` } ;
266+ const isValidObj = isValidJsObjectForStates ( functionInfo ) ;
267+ if ( ! isValidObj . isValid ) {
268+ return { code : 6 , error_message : `Invalid object for states: ${ isValidObj . invalidPath } ` } ;
264269 }
265270 const parsedPath = ChainUtil . parsePath ( functionPath ) ;
271+ const isValidPath = isValidPathForStates ( parsedPath ) ;
272+ if ( ! isValidPath . isValid ) {
273+ return { code : 7 , error_message : `Invalid path: ${ isValidPath . invalidPath } ` } ;
274+ }
266275 if ( ! this . getPermissionForFunction ( parsedPath , address ) ) {
267276 return { code : 3 , error_message : `No write_function permission on: ${ functionPath } ` } ;
268277 }
@@ -276,11 +285,15 @@ class DB {
276285 // TODO(seo): Add rule config sanitization logic (e.g. dup path variables,
277286 // multiple path variables).
278287 setRule ( rulePath , rule , address ) {
279- const { isValid , invalidPath } = isValidJsObjectForStates ( rule ) ;
280- if ( ! isValid ) {
281- return { code : 6 , error_message : `Invalid object for states: ${ invalidPath } ` } ;
288+ const isValidObj = isValidJsObjectForStates ( rule ) ;
289+ if ( ! isValidObj . isValid ) {
290+ return { code : 6 , error_message : `Invalid object for states: ${ isValidObj . invalidPath } ` } ;
282291 }
283292 const parsedPath = ChainUtil . parsePath ( rulePath ) ;
293+ const isValidPath = isValidPathForStates ( parsedPath ) ;
294+ if ( ! isValidPath . isValid ) {
295+ return { code : 7 , error_message : `Invalid path: ${ isValidPath . invalidPath } ` } ;
296+ }
284297 if ( ! this . getPermissionForRule ( parsedPath , address ) ) {
285298 return { code : 3 , error_message : `No write_rule permission on: ${ rulePath } ` } ;
286299 }
@@ -292,11 +305,15 @@ class DB {
292305
293306 // TODO(seo): Add owner config sanitization logic.
294307 setOwner ( ownerPath , owner , address ) {
295- const { isValid , invalidPath } = isValidJsObjectForStates ( owner ) ;
296- if ( ! isValid ) {
297- return { code : 6 , error_message : `Invalid object for states: ${ invalidPath } ` } ;
308+ const isValidObj = isValidJsObjectForStates ( owner ) ;
309+ if ( ! isValidObj . isValid ) {
310+ return { code : 6 , error_message : `Invalid object for states: ${ isValidObj . invalidPath } ` } ;
298311 }
299312 const parsedPath = ChainUtil . parsePath ( ownerPath ) ;
313+ const isValidPath = isValidPathForStates ( parsedPath ) ;
314+ if ( ! isValidPath . isValid ) {
315+ return { code : 7 , error_message : `Invalid path: ${ isValidPath . invalidPath } ` } ;
316+ }
300317 if ( ! this . getPermissionForOwner ( parsedPath , address ) ) {
301318 return { code : 4 , error_message : `No write_owner or branch_owner permission on: ${ ownerPath } ` } ;
302319 }
0 commit comments