Skip to content

Commit

Permalink
feat: 🎸 QueryACL - query some account info
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilingXinyi committed Mar 4, 2021
1 parent 3a3b1fb commit a00c0a4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Created by baidu on 2020/7/20
*/

import {ContractRequesttModel} from './types';
import {ContractRequesttModel, ContractInfo} from './types';
import * as Requests from './requests';

export default class Contract {
Expand Down Expand Up @@ -37,6 +37,24 @@ export default class Contract {
return invokeRequests;
}

async queryACL(node: string, chain: string, accountName: string, contarctInfo?: ContractInfo) {
let body = {
bcname: chain,
accountName
}

if (contarctInfo) {
body = {
...body,
// @ts-ignore
contractName: contarctInfo.contarctName,
methodName: contarctInfo.contractMethod
}
}

return Requests.queryACL(node, body);
}

contarctAccounts(node: string, chain: string, address: string) {
const body = {
bcname: chain,
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
TransactionModel,
AuthModel,
Plugin,
ContractRequesttModel
ContractRequesttModel,
ContractInfo
} from './types';

export default class XuperSDK implements XuperSDKInterface {
Expand Down Expand Up @@ -531,6 +532,17 @@ export default class XuperSDK implements XuperSDKInterface {
return this.invoke(invokeRequests, amount, account)
}

async queryACL(
contractAccount: string,
contractInfo?: ContractInfo
): Promise<any> {

const node = this.options.node;
const bcname = this.options.chain;

return this.contractInstance.queryACL(node, bcname, contractAccount, contractInfo);
}

transactionIdToHex(t: Required<string>): string {
if (!t) {
throw Errors.PARAMETER_EMPTY_FUNC();
Expand Down
12 changes: 12 additions & 0 deletions src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ const gRPCPromise = (service: string, body: any) => {
}));
};

const wrapperRequest = (request: {gRPCService: string; httpService: string}, body: any) => {
if (client) {
return gRPCPromise(request.gRPCService, body);
}
else {
return postRequest(request.httpService, body);
}
}

export const getStatus = (node: string, body: any): Promise<any> => {
if (client) {
return gRPCPromise('GetBlockChainStatus', body);
Expand Down Expand Up @@ -256,3 +265,6 @@ export const accountList = (node: string, body: any): Promise<any> => {
return postRequest(target, body);
}
};

export const queryACL = (node: string, body: any): Promise<any> =>
wrapperRequest({gRPCService: 'QueryACL', httpService: `${node}/v1/query_acl`}, body);
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,10 @@ export type TransactionModel = {
*/
contractRequests?: any[];
}

/* ---------- Contract ---------- */

export type ContractInfo = {
contarctName: string;
contractMethod: string;
}

0 comments on commit a00c0a4

Please sign in to comment.