@@ -19,9 +19,10 @@ const { toBN } = Web3.utils;
1919
2020export default async function createContractApi ( { web3, archon, linguo, arbitrator } ) {
2121 const chainId = await web3 . eth . getChainId ( ) ;
22- const firstRelevantBlock = firstRelevantBlockByChainId [ chainId ] ?? 0 ;
23- const evidenceDisplayInterfaceURI = evidenceDisplayURIByChainId [ chainId ] ?? evidenceDisplayURIByChainId [ 1 ] ;
24- const dynamicScriptURI = dynamicScriptURIByChainId [ chainId ] ?? dynamicScriptURIByChainId [ 1 ] ;
22+ const firstRelevantBlock = chainIdToFirstRelevantBlock [ chainId ] ?? 0 ;
23+ const evidenceDisplayInterfaceURI =
24+ chainIdToCurrentEvidenceDisplayInterfaceURI [ chainId ] ?? chainIdToCurrentEvidenceDisplayInterfaceURI [ 1 ] ;
25+ const dynamicScriptURI = chainIdToCurrentDynamicScriptURI [ chainId ] ?? chainIdToCurrentDynamicScriptURI [ 1 ] ;
2526
2627 const metadataStore = localforage . createInstance ( {
2728 name : `task-metadata@eip155:${ chainId } ` ,
@@ -41,7 +42,6 @@ export default async function createContractApi({ web3, archon, linguo, arbitrat
4142 const tx = linguo . methods . createTask ( deadline , minPrice , metaEvidence ) . send ( {
4243 from,
4344 gas,
44-
4545 value : maxPrice ,
4646 } ) ;
4747
@@ -501,7 +501,6 @@ export default async function createContractApi({ web3, archon, linguo, arbitrat
501501 } ;
502502 }
503503 }
504-
505504 async function _getPastEvents ( contract , eventName , { filter, fromBlock = 0 , toBlock = 'latest' } = { } ) {
506505 return promiseRetry (
507506 ( ) =>
@@ -725,15 +724,23 @@ export default async function createContractApi({ web3, archon, linguo, arbitrat
725724 [ account ] : 'Requester' ,
726725 } ,
727726 metadata : {
727+ ...metadata ,
728728 /**
729729 * v1:
730730 * - Removed `text` field
731731 * - Added `wordCount` field
732732 * - `originalTextFile` is mandatory
733733 */
734- __v : 1 ,
735- ...metadata ,
734+ __v : '1' ,
736735 } ,
736+ arbitrableChainID : chainId ,
737+ /**
738+ * v1.0.0:
739+ * - Removed `text` field
740+ * - Added `wordCount` field
741+ * - `originalTextFile` is mandatory
742+ */
743+ _v : '1.0.0' ,
737744 } ) ;
738745
739746 const { path } = await ipfs . publish ( 'linguo-meta-evidence.json' , JSON . stringify ( metaEvidence ) ) ;
@@ -755,28 +762,15 @@ export default async function createContractApi({ web3, archon, linguo, arbitrat
755762 }
756763
757764 function _validateMetaEvidence ( metaEvidence ) {
758- const onlyRelevantFields = pick ( [
759- 'title' ,
760- 'description' ,
761- 'rulingOptions' ,
762- 'category' ,
763- 'question' ,
764- 'fileURI' ,
765- 'evidenceDisplayInterfaceURI' ,
766- 'dynamicScriptURI' ,
767- ] ) ;
768-
769- const currentTemplate = {
770- ...onlyRelevantFields ( metaEvidenceTemplate ) ,
771- evidenceDisplayInterfaceURI,
772- dynamicScriptURI,
773- } ;
765+ const onlyStaticFields = pick ( [ 'title' , 'description' , 'rulingOptions' , 'category' , 'question' , 'fileURI' ] ) ;
774766
775- const templatesToCompare = [ currentTemplate ] ;
767+ const areStaticFieldsValid = deepEqual ( onlyStaticFields ( metaEvidence ) , onlyStaticFields ( metaEvidenceTemplate ) ) ;
768+ const isDynamicScriptValid =
769+ chainIdToValidDynamicScriptURIs [ chainId ] ?. includes ( metaEvidence . dynamicScriptURI ) ?? false ;
770+ const isEvidenceDisplayInterfaceValid =
771+ chainIdToValidEvidenceDisplayInterfaceURIs [ chainId ] ?. includes ( metaEvidence . evidenceDisplayInterfaceURI ) ?? false ;
776772
777- const metaEvidenceToCompare = onlyRelevantFields ( metaEvidence ) ;
778-
779- const isValid = ! ! templatesToCompare . some ( template => deepEqual ( metaEvidenceToCompare , template ) ) ;
773+ const isValid = areStaticFieldsValid && isDynamicScriptValid && isEvidenceDisplayInterfaceValid ;
780774
781775 if ( ! isValid ) {
782776 throw new Error ( 'This translation task is not valid.' ) ;
@@ -843,22 +837,40 @@ export default async function createContractApi({ web3, archon, linguo, arbitrat
843837}
844838
845839// TODO: Add xDAI params
846- const firstRelevantBlockByChainId = {
840+ const chainIdToFirstRelevantBlock = {
847841 1 : 11237802 ,
848842 42 : 0 ,
849843 77 : 22580202 ,
850844} ;
851845
852- const evidenceDisplayURIByChainId = {
846+ const chainIdToCurrentEvidenceDisplayInterfaceURI = {
853847 1 : '/ipfs/QmXGDMfcxjfQi5SFwpBSb73pPjoZq2N8c6eWCgxx8pVqj7/index.html' ,
854848 42 : '/ipfs/QmYbtF7K6qCfSYfu2k6nYnVRY8HY97rEAF6mgBWtDgfovw/index.html' ,
855- 77 : '/ipfs/Qmf7zuZAkc3Dms4QXXuQkuJDamB4Hm2ASG24Yy4A6EY2gs /linguo-evidence-display/index.html' ,
849+ 77 : '/ipfs/Qmb5n6PgbshktJqGpwMAxP1moXEPaqq7ZvRufeXXhSPXxW /linguo-evidence-display/index.html' ,
856850} ;
857851
858- const dynamicScriptURIByChainId = {
852+ /**
853+ * Keeps track of historical values for evidenceDisplayInterfaceURI
854+ */
855+ const chainIdToValidEvidenceDisplayInterfaceURIs = {
856+ 1 : [ chainIdToCurrentEvidenceDisplayInterfaceURI [ 1 ] ] ,
857+ 42 : [ chainIdToCurrentEvidenceDisplayInterfaceURI [ 42 ] ] ,
858+ 77 : [ chainIdToCurrentEvidenceDisplayInterfaceURI [ 77 ] ] ,
859+ } ;
860+
861+ const chainIdToCurrentDynamicScriptURI = {
859862 1 : '/ipfs/QmchWC6L3dT23wwQiJJLWCeS1EDnDYrLcYat93C4Lm4P4E/linguo-dynamic-script.js' ,
860863 42 : '/ipfs/QmZFcqdsR76jyHyLsBefc4SBuegj2boBDr2skxGauM5DNf/linguo-dynamic-script.js' ,
861- 77 : '/ipfs/QmXERKZXNmvX3nvHg8SGceG5bpkbjGyxYEcKP6W5m4NrHk/linguo-script.js' ,
864+ 77 : '/ipfs/QmPAHCRtSU844fdjNoEws8AgTpzzwsYwMF2wydtpvXAcoZ/linguo-script.js' ,
865+ } ;
866+
867+ /**
868+ * Keeps track of historical values for evidenceDisplayInterfaceURI
869+ */
870+ const chainIdToValidDynamicScriptURIs = {
871+ 1 : [ chainIdToCurrentDynamicScriptURI [ 1 ] ] ,
872+ 42 : [ chainIdToCurrentDynamicScriptURI [ 42 ] ] ,
873+ 77 : [ chainIdToCurrentDynamicScriptURI [ 77 ] ] ,
862874} ;
863875
864876const getFileTypeFromPath = path => ( path ?? '' ) . split ( '.' ) . slice ( - 1 ) ?. [ 0 ] ;
0 commit comments