Skip to content
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

改进并统一智能合约 ABI 调用方式 #102

Open
Tracked by #101
ourai opened this issue Jan 24, 2025 · 0 comments
Open
Tracked by #101

改进并统一智能合约 ABI 调用方式 #102

ourai opened this issue Jan 24, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@ourai
Copy link
Member

ourai commented Jan 24, 2025

对智能合约 ABI 的调用使用 obj.method(params) 的形式替代 readContract(config, { address, abi, functionName, args }),这样更符合直觉且更简洁:

// 构造一个拥有 ABI 方法的对象
function constructMethods(addr, abi) {}

// 添加请求返回拦截器
function setInterceptor(interceptor) {}

export { constructMethods, setInterceptor };

业务模块中的请求使用简单定义的异步函数:

// 通过 HTTP API 获取列表
async function getList(params) {
  return legacyClient.get('/get/list', { params });
}

// 通过智能合约 ABI 获取详情
async function getOne(params) {
  return contractA.getOne(params);
}

// 通过 HTTP API 新增数据
async function insertOne(data) {
  return httpClient.post('/insert/one', data);
}

// 通过智能合约 ABI 修改数据
async function updateOne(data) {
  return contractB.updateOne(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant