-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from steemit/add-broadcast-addAccountAuth
Add broadcast add account auth
- Loading branch information
Showing
7 changed files
with
3,347 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,9 @@ | |
"presets": [ | ||
"es2015", | ||
"es2017" | ||
], | ||
"plugins": [ | ||
"transform-async-to-generator", | ||
"transform-regenerator" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import api from "../api"; | ||
|
||
const defaultWeight = 1; | ||
|
||
exports = module.exports = steemBroadcast => { | ||
steemBroadcast.addAccountAuth = async ( | ||
activeWif, | ||
username, | ||
authorizedUsername, | ||
role = "posting", | ||
cb | ||
) => { | ||
const [userAccount] = await api.getAccountsAsync([username]); | ||
|
||
const updatedAuthority = userAccount[role]; | ||
const authorizedAccounts = updatedAuthority.account_auths.map( | ||
auth => auth[0] | ||
); | ||
const hasAuthority = authorizedAccounts.indexOf(authorizedUsername) !== -1; | ||
|
||
if (hasAuthority) { | ||
// user does already exist in authorized list | ||
return cb(null, null); | ||
} | ||
updatedAuthority.account_auths.push([authorizedUsername, defaultWeight]); | ||
const owner = role === "owner" ? updatedAuthority : undefined; | ||
const active = role === "active" ? updatedAuthority : undefined; | ||
const posting = role === "posting" ? updatedAuthority : undefined; | ||
/** Add authority on user account */ | ||
steemBroadcast.accountUpdate( | ||
activeWif, | ||
userAccount.name, | ||
owner, | ||
active, | ||
posting, | ||
userAccount.memo_key, | ||
userAccount.json_metadata, | ||
cb | ||
); | ||
}; | ||
|
||
steemBroadcast.removeAccountAuth = async ( | ||
activeWif, | ||
username, | ||
authorizedUsername, | ||
role = "posting", | ||
cb | ||
) => { | ||
const [userAccount] = await api.getAccountsAsync([username]); | ||
const updatedAuthority = userAccount[role]; | ||
const totalAuthorizedUser = updatedAuthority.account_auths.length; | ||
for (let i = 0; i < totalAuthorizedUser; i++) { | ||
const user = updatedAuthority.account_auths[i]; | ||
if (user[0] === authorizedUsername) { | ||
updatedAuthority.account_auths.splice(i, 1); | ||
break; | ||
} | ||
} | ||
// user does not exist in authorized list | ||
if (totalAuthorizedUser === updatedAuthority.account_auths.length) { | ||
return cb(null, null); | ||
} | ||
|
||
const owner = role === "owner" ? updatedAuthority : undefined; | ||
const active = role === "active" ? updatedAuthority : undefined; | ||
const posting = role === "posting" ? updatedAuthority : undefined; | ||
|
||
steemBroadcast.accountUpdate( | ||
activeWif, | ||
userAccount.name, | ||
owner, | ||
active, | ||
posting, | ||
userAccount.memo_key, | ||
userAccount.json_metadata, | ||
cb | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.