Skip to content

Commit

Permalink
Add discovery of multi-sig accounts using account ids fix bitshares#414
Browse files Browse the repository at this point in the history
  • Loading branch information
svk31 committed Sep 16, 2017
1 parent bd63b81 commit eb1b83b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
33 changes: 24 additions & 9 deletions app/stores/AccountRefsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class AccountRefsStore extends BaseStore {
}

_getInitialState() {
this.chainstore_account_ids_by_key = null
this.chainstore_account_ids_by_key = null;
this.chainstore_account_ids_by_account = null;
return {
account_refs: Immutable.Set()
// loading_account_refs: false
Expand All @@ -34,24 +35,29 @@ class AccountRefsStore extends BaseStore {
loadDbData() {
// this.setState(this._getInitialState())
this.chainstore_account_ids_by_key = null;
this.chainstore_account_ids_by_account = null;
this.state = {account_refs: Immutable.Set()};
return loadNoAccountRefs()
.then( no_account_refs => this.no_account_refs = no_account_refs )
.then( ()=> this.chainStoreUpdate() );
}

chainStoreUpdate() {
if(this.chainstore_account_ids_by_key === ChainStore.account_ids_by_key) return
this.chainstore_account_ids_by_key = ChainStore.account_ids_by_key
this.checkPrivateKeyStore()
if(
this.chainstore_account_ids_by_key === ChainStore.account_ids_by_key &&
this.chainstore_account_ids_by_account === ChainStore.account_ids_by_account
) return;
this.chainstore_account_ids_by_key = ChainStore.account_ids_by_key;
this.chainstore_account_ids_by_account = ChainStore.account_ids_by_account;
this.checkPrivateKeyStore();
}

checkPrivateKeyStore() {
var no_account_refs = this.no_account_refs
var account_refs = Immutable.Set()
let no_account_refs = this.no_account_refs
let account_refs = Immutable.Set()
PrivateKeyStore.getState().keys.keySeq().forEach( pubkey => {
if(no_account_refs.has(pubkey)) return
var refs = ChainStore.getAccountRefsOfKey(pubkey)
let refs = ChainStore.getAccountRefsOfKey(pubkey)
if(refs === undefined) return
if( ! refs.size) {
// Performance optimization...
Expand All @@ -61,7 +67,7 @@ class AccountRefsStore extends BaseStore {
{
// Do Not block brainkey generated keys.. Those are new and
// account references may be pending.
var private_key_object = PrivateKeyStore.getState().keys.get(pubkey)
let private_key_object = PrivateKeyStore.getState().keys.get(pubkey)
if( typeof private_key_object.brainkey_sequence === 'number' ) {
return
}
Expand All @@ -71,7 +77,16 @@ class AccountRefsStore extends BaseStore {
}
account_refs = account_refs.add(refs.valueSeq())
})
account_refs = account_refs.flatten()
account_refs = account_refs.flatten();

/* Discover accounts referenced by account name in permissions */
account_refs.forEach(account => {
let refs = ChainStore.getAccountRefsOfAccount(account);
if(refs === undefined) return;
if( ! refs.size) return;
account_refs = account_refs.add(refs.valueSeq());
});
account_refs = account_refs.flatten();
if( ! this.state.account_refs.equals(account_refs)) {
// console.log("AccountRefsStore account_refs",account_refs.size);
this.setState({account_refs})
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"alt-container": "^1.0.0",
"alt-react": "0.0.1",
"bignumber.js": "^4.0.0",
"bitsharesjs": "^1.2.9",
"bitsharesjs": "^1.2.10",
"classnames": "^2.2.1",
"cookies-js": "^1.2.1",
"counterpart": "^0.17.1",
Expand Down

0 comments on commit eb1b83b

Please sign in to comment.