Skip to content

Commit

Permalink
Merge pull request #549 from EYBlockchain/david/proposer-offchain
Browse files Browse the repository at this point in the history
David/proposer offchain
  • Loading branch information
ChaitanyaKonda authored Mar 10, 2022
2 parents 4aeee1e + 2998c31 commit a52df0b
Show file tree
Hide file tree
Showing 40 changed files with 3,652 additions and 3,618 deletions.
50 changes: 37 additions & 13 deletions cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,15 @@ class Nf3 {
the proposer.
@method
@async
@param {string} Proposer REST API URL with format https://xxxx.xxx.xx
@returns {Promise} A promise that resolves to the Ethereum transaction receipt.
*/
async registerProposer() {
async registerProposer(url) {
const res = await axios.post(`${this.optimistBaseUrl}/proposer/register`, {
address: this.ethereumAddress,
url,
});
logger.debug(`Proposer Registered with address ${this.ethereumAddress} and URL ${url}`);
return this.submitTransaction(
res.data.txDataToSign,
this.proposersContractAddress,
Expand Down Expand Up @@ -637,23 +640,19 @@ class Nf3 {
}

/**
Adds a new Proposer peer to a list of proposers that are available for accepting
offchain (direct) transfers and withdraws. The client will submit direct transfers
and withdraws to all of these peers.
Update Proposers URL
@method
@async
@param {string} peerUrl - the URL of the Proposer being added. This will be from
the point of view of nightfall-client, not the SDK user (e.g. 'http://optimist1:80').
Nightfall-client will use this URL to contact the Proposer.
@param {string} Proposer REST API URL with format https://xxxx.xxx.xx
@returns {array} A promise that resolves to the Ethereum transaction receipt.
*/
async addPeer(peerUrl) {
if (!this.ethereumAddress)
throw new Error('Cannot add peer if the Ethereum address for the user is not defined');
// the peerUrl is from the point of view of the Client e.g. 'http://optimist1:80'
return axios.post(`${this.clientBaseUrl}/peers/addPeers`, {
async updateProposer(url) {
const res = await axios.post(`${this.optimistBaseUrl}/proposer/update`, {
address: this.ethereumAddress,
enode: peerUrl,
url,
});
logger.debug(`Proposer with address ${this.ethereumAddress} updated to URL ${url}`);
return this.submitTransaction(res.data.txDataToSign, this.proposersContractAddress, 0);
}

/**
Expand Down Expand Up @@ -689,6 +688,22 @@ class Nf3 {
return newGasBlockEmitter;
}

/**
Send offchain transaction to Optimist
@method
@async
@param {string} transaction
@returns {array} A promise that resolves to the API call status
*/
async sendOffchainTransaction(transaction) {
const res = axios.post(
`${this.optimistBaseUrl}/proposer/offchain-transaction`,
{ transaction },
{ timeout: 3600000 },
);
return res.status;
}

/**
Returns an emitter, whose 'data' event fires whenever a block is
detected, passing out the transaction needed to propose the block. This
Expand Down Expand Up @@ -807,6 +822,15 @@ class Nf3 {
return res.data.balance;
}

async getLayer2BalancesUnfiltered({ ercList } = {}) {
const res = await axios.get(`${this.clientBaseUrl}/commitment/balance`, {
params: {
compressedPkd: ercList,
},
});
return res.data.balance;
}

/**
Returns the balance of tokens held in layer 2
@method
Expand Down
Loading

0 comments on commit a52df0b

Please sign in to comment.