-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Considering rank service at server side #29
Comments
have to make event listener |
const sub = this.DepositManager.events.Deposited({
fromBlock: this.blockNumber,
}, function (error, event){
console.log(event);
})
.on('data', function (event){
console.log(event); // same results as the optional callback above
})
.on('changed', function (event){
// remove event from local database
})
.on('error', console.error); |
also not working const subscription = this.web3.eth.subscribe('logs', {
address: this.DepositManager._address,
}, function (error, result){
if (error)
console.log('error', error);
console.log('result', result);
}); |
it works: make rootchain blocktime 10 seconds. otherwise we can meet this error again. |
reference: MetaMask/metamask-extension#5458 |
after block time set 10s, all event listeners work. so we use this one. this.DepositManager.events.Deposited({
fromBlock: this.blockNumber,
}, function (error, event){
console.log(event);
})
.on('data', function (event){
console.log(event); // same results as the optional callback above
})
.on('changed', function (event){
// remove event from local database
})
.on('error', console.error); |
Klaytn..? 1s? |
unsubscribe event listener |
we need to check |
before sign in: async setAccountsDepositedWithPower (context) {
const web3 = context.state.web3;
const PowerTON = context.state.PowerTON;
const DepositManager = context.state.DepositManager;
const depositedEvent = web3.eth.abi.encodeEventSignature('Deposited(address,address,uint256)');
const deployedAt = DepositManager.transactionConfirmationBlocks;
// event Deposited(address indexed rootchain, address depositor, uint256 amount);
const events = await DepositManager.getPastEvents('Deposited', {
fromBlock: deployedAt,
toBlock: 'latest',
topics: [depositedEvent],
});
const depositors = uniq(events.map(event => event.returnValues.depositor));
const accounts = depositors.map(async depositor => {
const power = await PowerTON.methods.powerOf(depositor).call();
return {
address: depositor.toLowerCase(),
power: _POWER.ray(power.toString()),
};
});
context.commit('SET_ACCOUNTS_DEPOSITED_WITH_POWER', await Promise.all(accounts));
}, after sign in: async subscribe () {
this.depositedEventSubscription = this.DepositManager.events.Deposited({
fromBlock: 'latest',
}, async (error, event) => {
if (error) {
//
}
const result = event.returnValues;
this.$store.dispatch('addAccountDepositedWithPower', result.depositor);
});
}, async addAccountDepositedWithPower (context, depositor) {
const PowerTON = context.state.PowerTON;
const power = await PowerTON.methods.powerOf(depositor).call();
context.commit('ADD_ACCOUNT_DEPOSITED_WITH_POWER', {
address: depositor.toLowerCase(),
power: _POWER.ray(power.toString()),
}); ADD_ACCOUNT_DEPOSITED_WITH_POWER: (state, accountWithPower) => {
const findAccount = (account) => account.address.toLowerCase() === accountWithPower.address.toLowerCase();
const index = state.accountsDepositedWithPower.findIndex(findAccount);
if (index > -1) {
Vue.set(state.accountsDepositedWithPower, index, accountWithPower);
} else {
state.accountsDepositedWithPower.push(accountWithPower);
}
}, |
before user sign in, we can get all the accounts that have power. but after user sign in,
vapp
can't detect event for other user's deposit.so we have to consider to make rank service at server side.
The text was updated successfully, but these errors were encountered: