Browse Source

fix the interface: ledgers/xxx/settings

tags/1.0.0
zhaoguangwei 6 years ago
parent
commit
de75122c6f
1 changed files with 39 additions and 8 deletions
  1. +39
    -8
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocationProxy.java

+ 39
- 8
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocationProxy.java View File

@@ -1,22 +1,53 @@
package com.jd.blockchain.transaction; package com.jd.blockchain.transaction;


import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.serialize.binary.BinarySerializeUtils;

import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method; import java.lang.reflect.Method;


public class ContractInvocationProxy implements InvocationHandler {
private String contractMessage;
public class ContractInvocationProxy implements InvocationHandler {

// private String contractMessage;

private Bytes contractAddress;

private ContractType contractType;


private ContractEventSendOperationBuilder sendOpBuilder; private ContractEventSendOperationBuilder sendOpBuilder;

public ContractInvocationProxy(Bytes contractAddress, ContractType contractType,
ContractEventSendOperationBuilder sendOpBuilder) {
this.contractAddress = contractAddress;
this.contractType = contractType;
this.sendOpBuilder = sendOpBuilder;
}


@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// TODO Auto-generated method stub

if(contractType == null){
return "contractType == null, no invoke really.";
}

String event = contractType.getEvent(method);
if (event == null) {
// 适配 Object 对象的方法;
// toString 方法;
return String.format("[%s]-%s", contractAddress, contractType.toString());

// hashCode 方法;
}
// 合约方法;
byte[] argBytes = serializeArgs(args);
sendOpBuilder.send(contractAddress, event, argBytes);

// TODO: 暂时未考虑有返回值的情况;
return null; return null;
} }


private byte[] serializeArgs(Object[] args) {
// TODO 根据方法参数的定义序列化参数;
return BinarySerializeUtils.serialize(args);
}
} }

Loading…
Cancel
Save