use of org.nutz.mvc.annotation.At in project nutzboot by nutzam.
the class EthModule method sendTransaction.
// @POST
@At("/eth/sendTransaction/?/?")
public NutMap sendTransaction(String from, String to, @Param("wei") double wei) {
// from 必须是本地账号
// to 必须是address
NutMap re = new NutMap();
// 检查转账金额
if (wei < 0.01) {
re.put("msg", "起码转账 0.01 eth");
return re;
}
if (wei > 100) {
re.put("msg", "最多转账 100 eth");
return re;
}
Web3jAccount account = web3jCredentials.get(from);
if (account == null) {
return re.setv("msg", "不存在这个本地账号: " + from);
}
// 发起转账
BigInteger value = Convert.toWei(new BigDecimal(wei), Convert.Unit.ETHER).toBigInteger();
Transaction transaction = Transaction.createEtherTransaction(account.getAddress(), null, null, null, to, value);
try {
EthSendTransaction est = web3jAdmin.personalSendTransaction(transaction, account.getPassword()).send();
String hash = est.getTransactionHash();
return re.setv("ok", true).setv("hash", hash);
} catch (Exception e) {
log.warn("转账失败!!!", e);
return re.setv("msg", e.getMessage());
}
}
use of org.nutz.mvc.annotation.At in project incubator-skywalking by apache.
the class ActionMethodInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
PathMappingCache pathMappingCache = (PathMappingCache) objInst.getSkyWalkingDynamicField();
String requestURL = pathMappingCache.findPathMapping(method);
if (requestURL == null) {
At methodRequestMapping = method.getAnnotation(At.class);
if (methodRequestMapping.value().length > 0) {
requestURL = methodRequestMapping.value()[0];
} else {
requestURL = "";
}
pathMappingCache.addPathMapping(method, requestURL);
requestURL = pathMappingCache.findPathMapping(method);
}
HttpServletRequest request = Mvcs.getReq();
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(request.getHeader(next.getHeadKey()));
}
AbstractSpan span = ContextManager.createEntrySpan(requestURL, contextCarrier);
Tags.URL.set(span, request.getRequestURL().toString());
Tags.HTTP.METHOD.set(span, request.getMethod());
span.setComponent(ComponentsDefine.NUTZ_MVC_ANNOTATION);
SpanLayer.asHttp(span);
}
use of org.nutz.mvc.annotation.At in project incubator-skywalking by apache.
the class ActionConstructorInterceptor method onConstruct.
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
String basePath = "";
At basePathRequestMapping = objInst.getClass().getAnnotation(At.class);
if (basePathRequestMapping != null) {
basePath = basePathRequestMapping.value()[0];
}
PathMappingCache pathMappingCache = new PathMappingCache(basePath);
objInst.setSkyWalkingDynamicField(pathMappingCache);
}
use of org.nutz.mvc.annotation.At in project nutz by nutzam.
the class UserModule method login.
@Filters
@POST
@At
public NutMap login(String username, String password, HttpSession session) {
NutMap re = new NutMap("ok", false);
if (Strings.isBlank(username) || Strings.isBlank(password)) {
log.debug("username or password is null");
return re.setv("msg", "用户名或密码不能为空");
}
User user = dao.fetch(User.class, username);
if (user == null) {
log.debug("no such user = " + username);
return re.setv("msg", "没有该用户");
}
String tmp = Lang.digest("SHA-256", user.getSalt() + password);
if (!tmp.equals(user.getPassword())) {
log.debug("password is wrong");
return re.setv("msg", "密码错误");
}
session.setAttribute("me", user);
return re.setv("ok", true);
}
use of org.nutz.mvc.annotation.At in project nutzboot by nutzam.
the class UserModule method apitest.
/**
* 这是演示api调用的入口,会顺序调用一堆请求,请关注日志
*/
@Ok("raw")
@At
public String apitest() {
List<User> users = userService.list();
log.info("users=" + Json.toJson(users));
User haoqoo = userService.add("haoqoo", 19);
User wendal = userService.add("wendal", 28);
users = userService.list();
log.info("users=" + Json.toJson(users));
userService.delete(haoqoo.getId());
userService.delete(wendal.getId());
users = userService.list();
log.info("users=" + Json.toJson(users));
return "done";
}
Aggregations