@@ -2,6 +2,17 @@ import { DDO } from '@oceanprotocol/ddo-js'
22import { PolicyServerResult } from '../../@types/policyServer.js'
33import { isDefined } from '../../utils/util.js'
44import { BaseFileObject } from '../../@types/fileObject.js'
5+ import { OceanNode } from '../../OceanNode.js'
6+
7+ export function attachNodeAddress (
8+ command : Record < string , any > ,
9+ nodeAddress : string
10+ ) : Record < string , any > {
11+ return {
12+ ...command ,
13+ nodeAddress
14+ }
15+ }
516
617export class PolicyServer {
718 serverUrl : string
@@ -12,9 +23,18 @@ export class PolicyServer {
1223 this . apikey = process . env . POLICY_SERVER_API_KEY
1324 }
1425
26+ private attachNodeAddress ( command : Record < string , any > ) : Record < string , any > {
27+ const node = OceanNode . getInstance ( )
28+ const keyManager = node . getKeyManager ( )
29+ const nodeAddress = keyManager . getEthWallet ( ) . address
30+ return attachNodeAddress ( command , nodeAddress )
31+ }
32+
1533 private async askServer ( command : any ) : Promise < PolicyServerResult > {
1634 if ( ! this . serverUrl ) return { success : true , message : '' , httpStatus : 404 }
1735 let response
36+ const commandWithNodeAddress = this . attachNodeAddress ( command )
37+
1838 const headers : Record < string , string > = {
1939 'Content-Type' : 'application/json'
2040 }
@@ -25,7 +45,7 @@ export class PolicyServer {
2545 response = await fetch ( this . serverUrl , {
2646 headers,
2747 method : 'POST' ,
28- body : JSON . stringify ( command )
48+ body : JSON . stringify ( commandWithNodeAddress )
2949 } )
3050 } catch ( e ) {
3151 const errorText =
0 commit comments