Skip to content

Commit

Permalink
ADD: Fee Recipient via API (#622)
Browse files Browse the repository at this point in the history
* ADD: Fee Recipient via API

* update names

* FIX: recipient import
  • Loading branch information
NeoPlays authored Sep 1, 2022
1 parent 6ab264f commit 0edbd41
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 39 deletions.
78 changes: 39 additions & 39 deletions controls/roles/validator-fee-recipient-api/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@

########
# fee recipient
# - block:
# - name: Prysm - Get validator service's api token
# slurp:
# src: "{{ stereum_service_configuration.volumes | select('match', '.*\/opt\/app\/data\/wallets') | first | split(':') | first }}/auth-token"
# register: stereum_service_configuration_raw
# become: yes
# - include_tasks: fee_recipient.yaml
# vars:
# validator_port: 7500
# api_token: "{{ (stereum_service_configuration_raw.content | b64decode).splitlines() | last }}"
# loop: "{{ validator_keys }}"
# when: stereum_service_configuration.service == "PrysmValidatorService"
- block:
- name: Prysm - Get validator service's api token
slurp:
src: "{{ stereum_service_configuration.volumes | select('match', '.*\/opt\/app\/data\/wallets') | first | split(':') | first }}/auth-token"
register: stereum_service_configuration_raw
become: yes
- include_tasks: fee_recipient.yaml
vars:
validator_port: 7500
api_token: "{{ (stereum_service_configuration_raw.content | b64decode).splitlines() | last }}"
loop: "{{ validator_keys }}"
when: stereum_service_configuration.service == "PrysmValidatorService"

# - block:
# - name: Lighthouse - Get validator service's api token
# command: "docker exec -u 0 -w /opt/app/validator/validators stereum-{{ validator_service }} cat api-token.txt"
# changed_when: false
# register: api_token_lh
# become: yes
# - name: print token
# debug:
# msg: "{{ api_token_lh.stdout }}"
# - include_tasks: fee_recipient.yaml
# vars:
# validator_port: 5062
# api_token: "{{ api_token_lh.stdout }}"
# loop: "{{ validator_keys }}"
# when: stereum_service_configuration.service == "LighthouseValidatorService"
- block:
- name: Lighthouse - Get validator service's api token
command: "docker exec -u 0 -w /opt/app/validator/validators stereum-{{ validator_service }} cat api-token.txt"
changed_when: false
register: api_token_lh
become: yes
- name: print token
debug:
msg: "{{ api_token_lh.stdout }}"
- include_tasks: fee_recipient.yaml
vars:
validator_port: 5062
api_token: "{{ api_token_lh.stdout }}"
loop: "{{ validator_keys }}"
when: stereum_service_configuration.service == "LighthouseValidatorService"

# - block:
# - name: Nimbus - Get validator service's api token
# command: "docker exec -u 0 -w /opt/app/validators stereum-{{ validator_service }} cat api-token.txt"
# changed_when: false
# register: api_token_n
# become: yes
# - include_tasks: fee_recipient.yaml
# vars:
# validator_port: 5052
# api_token: "{{ api_token_n.stdout }}"
# loop: "{{ validator_keys }}"
# when: stereum_service_configuration.service == "NimbusBeaconService"
- block:
- name: Nimbus - Get validator service's api token
command: "docker exec -u 0 -w /opt/app/validators stereum-{{ validator_service }} cat api-token.txt"
changed_when: false
register: api_token_n
become: yes
- include_tasks: fee_recipient.yaml
vars:
validator_port: 5052
api_token: "{{ api_token_n.stdout }}"
loop: "{{ validator_keys }}"
when: stereum_service_configuration.service == "NimbusBeaconService"

- block:
- name: Teku - Get validator service's api token
Expand Down
23 changes: 23 additions & 0 deletions launcher/src/backend/ValidatorAccountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,29 @@ export class ValidatorAccountManager {
})

}

async addFeeRecipient(keys, address){
if(keys && keys.length != 0 && address){
const serviceID = keys[0].validatorID
const validatorKeys = keys.map(key => {
return {
pubkey: key.key,
recipient: address
}
})

try {
let run = await this.nodeConnection.runPlaybook('validator-fee-recipient-api', { stereum_role: 'validator-fee-recipient-api', validator_service: serviceID, validator_keys: validatorKeys })
//let logs = new RegExp(/^DATA: ({"msg":.*)/, 'gm').exec(await this.nodeConnection.playbookStatus(run.playbookRunRef))
//let result = (JSON.parse(logs[1])).msg
return run
} catch (err) {
log.error("Changing Fee Recipient Failed:\n", err)
return err
}
}
return 0
}

async getOperatorPageURL(pubKey){
const hash = crypto.createHash('sha256').update(pubKey).digest('hex')
Expand Down
5 changes: 5 additions & 0 deletions launcher/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ promiseIpc.on("refreshServiceInfos", async () => {
return await monitoring.refreshServiceInfos();
});


promiseIpc.on("addFeeRecipient", async (args) => {
return await validatorAccountManager.addFeeRecipient(args.keys, args.address)
})

promiseIpc.on("getOperatorPageURL", async (args) => {
return await validatorAccountManager.getOperatorPageURL(args);
});
Expand Down
4 changes: 4 additions & 0 deletions launcher/src/store/ControlService.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ class ControlService extends EventEmitter {
return await this.promiseIpc.send("refreshServiceInfos"); // insert existing operator keys
}

async addFeeRecipient(args){
return await this.promiseIpc.send("addFeeRecipient", args) //
}

async getOperatorPageURL(args) {
return await this.promiseIpc.send("getOperatorPageURL", args); // insert existing operator keys
}
Expand Down

0 comments on commit 0edbd41

Please sign in to comment.