diff --git a/src/contract.ts b/src/contract.ts index 529840d..9c4998a 100644 --- a/src/contract.ts +++ b/src/contract.ts @@ -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 { @@ -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, diff --git a/src/index.ts b/src/index.ts index aed0b47..329247b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -18,7 +18,8 @@ import { TransactionModel, AuthModel, Plugin, - ContractRequesttModel + ContractRequesttModel, + ContractInfo } from './types'; export default class XuperSDK implements XuperSDKInterface { @@ -531,6 +532,17 @@ export default class XuperSDK implements XuperSDKInterface { return this.invoke(invokeRequests, amount, account) } + async queryACL( + contractAccount: string, + contractInfo?: ContractInfo + ): Promise { + + const node = this.options.node; + const bcname = this.options.chain; + + return this.contractInstance.queryACL(node, bcname, contractAccount, contractInfo); + } + transactionIdToHex(t: Required): string { if (!t) { throw Errors.PARAMETER_EMPTY_FUNC(); diff --git a/src/requests.ts b/src/requests.ts index 4ec5a79..cb563b2 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -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 => { if (client) { return gRPCPromise('GetBlockChainStatus', body); @@ -256,3 +265,6 @@ export const accountList = (node: string, body: any): Promise => { return postRequest(target, body); } }; + +export const queryACL = (node: string, body: any): Promise => + wrapperRequest({gRPCService: 'QueryACL', httpService: `${node}/v1/query_acl`}, body); diff --git a/src/types.ts b/src/types.ts index fa7a7b5..ee00f2e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -189,3 +189,10 @@ export type TransactionModel = { */ contractRequests?: any[]; } + +/* ---------- Contract ---------- */ + +export type ContractInfo = { + contarctName: string; + contractMethod: string; +}