11import axios from 'axios' ;
22import { ChainlinkNodeConfiguration } from './types' ;
33
4- const fs = require ( 'fs' ) ;
5-
6- const appRoot = require ( 'app-root-path' ) ;
7- const dslaProtocolJsonPath = `${ appRoot . path } /services/dsla-protocol.json` ;
8-
94let cookies = { } ;
105
116const getChainlinkSessionCookie = async ( node : ChainlinkNodeConfiguration ) => {
@@ -45,9 +40,11 @@ const getChainlinkAccounts = async (node: ChainlinkNodeConfiguration) => {
4540 return data ;
4641} ;
4742
48- const getChainlinkBridge = async ( node : ChainlinkNodeConfiguration ) => {
43+ const getChainlinkBridges = async ( node : ChainlinkNodeConfiguration ) => {
4944 const sessionCookie = await getChainlinkSessionCookie ( node ) ;
50- const { data } = await axios ( {
45+ const {
46+ data : { data } ,
47+ } = await axios ( {
5148 method : 'get' ,
5249 url : `${ node . restApiUrl } ${
5350 node . restApiPort ? ':' + node . restApiPort : undefined
@@ -58,15 +55,14 @@ const getChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
5855 } ,
5956 withCredentials : true ,
6057 } ) ;
61- const jobJson = JSON . parse ( fs . readFileSync ( dslaProtocolJsonPath ) ) ;
62- return data . data . find (
63- ( bridge ) => bridge . attributes . name === jobJson . tasks [ 0 ] . type
64- ) ;
58+ return data ;
6559} ;
6660
67- const getChainlinkJob = async ( node : ChainlinkNodeConfiguration ) => {
61+ const getChainlinkJobs = async ( node : ChainlinkNodeConfiguration ) => {
6862 const sessionCookie = await getChainlinkSessionCookie ( node ) ;
69- const { data } = await axios ( {
63+ const {
64+ data : { data } ,
65+ } = await axios ( {
7066 method : 'get' ,
7167 url : `${ node . restApiUrl } ${
7268 node . restApiPort ? ':' + node . restApiPort : undefined
@@ -77,10 +73,7 @@ const getChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
7773 } ,
7874 withCredentials : true ,
7975 } ) ;
80- const jobJson = JSON . parse ( fs . readFileSync ( dslaProtocolJsonPath ) ) ;
81- return data . data . find ( ( job ) =>
82- job . attributes . tasks . some ( ( task ) => task . type === jobJson . tasks [ 0 ] . type )
83- ) ;
76+ return data ;
8477} ;
8578
8679const getChainlinkJobId = async ( node : ChainlinkNodeConfiguration ) => {
@@ -99,7 +92,11 @@ const getChainlinkJobId = async (node: ChainlinkNodeConfiguration) => {
9992 return `0x${ data . data [ 0 ] . id } ` ;
10093} ;
10194
102- const postChainlinkJob = async ( node : ChainlinkNodeConfiguration ) => {
95+ const postChainlinkJob = async (
96+ node : ChainlinkNodeConfiguration ,
97+ jobName ,
98+ oracleContractAddress
99+ ) => {
103100 const sessionCookie = await getChainlinkSessionCookie ( node ) ;
104101 const { data } = await axios ( {
105102 method : 'post' ,
@@ -111,15 +108,41 @@ const postChainlinkJob = async (node: ChainlinkNodeConfiguration) => {
111108 'Content-Type' : 'application/json' ,
112109 } ,
113110 // eslint-disable-next-line global-require,import/no-dynamic-require
114- data : require ( dslaProtocolJsonPath ) ,
111+ data : {
112+ initiators : [
113+ {
114+ type : 'RunLog' ,
115+ params : {
116+ address : oracleContractAddress ,
117+ } ,
118+ } ,
119+ ] ,
120+ tasks : [
121+ {
122+ type : jobName ,
123+ } ,
124+ {
125+ type : 'copy' ,
126+ params : {
127+ copyPath : [ 'result' ] ,
128+ } ,
129+ } ,
130+ {
131+ type : 'ethtx' ,
132+ } ,
133+ ] ,
134+ minPayment : '10000000000' ,
135+ } ,
115136 withCredentials : true ,
116137 } ) ;
117138 return data ;
118139} ;
119140
120- const postChainlinkBridge = async ( node : ChainlinkNodeConfiguration ) => {
121- const jobJson = JSON . parse ( fs . readFileSync ( dslaProtocolJsonPath ) ) ;
122-
141+ const postChainlinkBridge = async (
142+ node : ChainlinkNodeConfiguration ,
143+ useCaseName ,
144+ externalAdapterUrl
145+ ) => {
123146 const sessionCookie = await getChainlinkSessionCookie ( node ) ;
124147 const { data } = await axios ( {
125148 method : 'post' ,
@@ -131,8 +154,8 @@ const postChainlinkBridge = async (node: ChainlinkNodeConfiguration) => {
131154 'Content-Type' : 'application/json' ,
132155 } ,
133156 data : {
134- name : jobJson . tasks [ 0 ] . type ,
135- url : node . externalAdapterUrl ,
157+ name : useCaseName ,
158+ url : externalAdapterUrl ,
136159 } ,
137160 withCredentials : true ,
138161 } ) ;
@@ -159,9 +182,9 @@ export {
159182 deleteJob ,
160183 postChainlinkJob ,
161184 postChainlinkBridge ,
162- getChainlinkJob ,
185+ getChainlinkJobs ,
163186 getChainlinkJobId ,
164- getChainlinkBridge ,
187+ getChainlinkBridges ,
165188 getChainlinkAccounts ,
166189 getChainlinkSessionCookie ,
167190} ;
0 commit comments