泰山众筹4.0阿凡达Avatar系统开发技术详细丨泰山众筹4.0阿凡达Avatar系统源码

简介: pragma solidity ^0.4.21;contract TransactionFee {// (1)uint public fee;

pragma solidity ^0.4.21;

contract TransactionFee {

// (1)

uint public fee;

// (2)

address public receiver;

// (3)

mapping (address => uint) public balances;

// (4)

event Sent(address from, address to, uint amount, bool sent);

// (5)

constructor(address _receiver, uint _fee) public {

receiver = _receiver;

fee = _fee;

}

// (6)

function getReceiverBalance() public view returns(uint) {

return receiver.balance;

}

// (7)

function sendTrx() public payable {

uint value = msg.value * fee / 100;

bool sent = receiver.send(value);

balances[receiver] += (value);

emit Sent(msg.sender, receiver, value, sent);

}

}

一旦我们创建了一个合约,我们必须编译并且创建源代码,这样我们才能够在我们的应用中部署合约并调用它的函数。有关 Solidity 编译器的相关信息,可以查阅官方网站:https://remix.ethereum.org

  1. 编译合约并创建源代码

Solidity 为编译器提供了最新的 Docker 镜像,正式版本标记为stable,来自于开发分支的不稳定版本标记为nightly。但是,Docker 镜像只包含编译器可执行文件,因此我们必须将 Solidity 合约输入文件进行持久化卷挂载。假设这些文件在我们运行 Docker 容器机器的目录 /home/docker 下,我们可以使用以下命令进行编译。这个命令创建了两个文件:一个二进制文件 .bin,是 EVM 可以解释的智能合约代码,另外一个是应用程序二进制接口文件.abi,里面定义了智能合约方法。

$ docker run --rm -v /home/docker:/build ethereum/solc:stable /build/TransactionFee.sol --bin --abi --optimize -o /build

编译输出文件在容器的/build目录下,并且持久化存储在/home/docker目录下。在编译结束后,该容器被删除,因为现在不需要它。我们可以使用 web3j 库来从编译后的智能合约文件中创建源代码。web3j 的可执行文件在${WEB3J_HOME}/bin目录下,在创建源代码时,需要指定.bin 和 .abi文件的路径,并且设定目标包名和目录。

$ web3j solidity generate /build/transactionfee.bin /build/transactionfee.abi -p pl.piomin.services.contract.model -o src/main/java/

Web3j 可执行文件在给定的包名下创建了 Java 源文件,该类名为 Solidity 智能合约名,下面是我们创建出来的源代码。

public class Transactionfee extends Contract {

private static final String BINARY = "608060405234801561..."

public static final String FUNC_GETRECEIVERBALANCE = "getReceiverBalance";

public static final String FUNC_BALANCES = "balances";

public static final String FUNC_SENDTRX = "sendTrx";

public static final String FUNC_FEE = "fee";

public static final String FUNC_RECEIVER = "receiver";

// ...

protected Transactionfee(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {

super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);

}

public RemoteCall getReceiverBalance() {

final Function function = new Function(FUNC_GETRECEIVERBALANCE,

Arrays.asList(),

Arrays.asList(new TypeReference() {}));

return executeRemoteCallSingleValueReturn(function, BigInteger.class);

}

public RemoteCall balances(String param0) {

final Function function = new Function(FUNC_BALANCES,

Arrays.asList(new org.web3j.abi.datatypes.Address(param0)),

Arrays.asList(new TypeReference() {}));

return executeRemoteCallSingleValueReturn(function, BigInteger.class);

}

public RemoteCall sendTrx(BigInteger weiValue) {

final Function function = new Function(

FUNC_SENDTRX,

Arrays.asList(),

Collections.emptyList());

return executeRemoteCallTransaction(function, weiValue);

}

public RemoteCall fee() {

final Function function = new Function(FUNC_FEE,

Arrays.asList(),

Arrays.asList(new TypeReference() {}));

return executeRemoteCallSingleValueReturn(function, BigInteger.class);

}

public RemoteCall receiver() {

final Function function = new Function(FUNC_RECEIVER,

Arrays.asList(),

Arrays.asList(new TypeReference

() {}));
return executeRemoteCallSingleValueReturn(function, String.class);

}

public static RemoteCall deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit, String _receiver, BigInteger _fee) {

String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.asList(new org.web3j.abi.datatypes.Address(_receiver),

new org.web3j.abi.datatypes.generated.Uint256(_fee)));

return deployRemoteCall(Transactionfee.class, web3j, credentials, gasPrice, gasLimit, BINARY, encodedConstructor);

}

public static RemoteCall deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit, String _receiver, BigInteger _fee) {

String encodedConstructor = FunctionEncoder.encodeConstructor(Arrays.asList(new org.web3j.abi.datatypes.Address(_receiver),

new org.web3j.abi.datatypes.generated.Uint256(_fee)));

return deployRemoteCall(Transactionfee.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, encodedConstructor);

}

相关文章
泰山众筹系统开发|解析泰山众筹模式火爆原因
最近也有不少读者私信问我这个模式,今天就在这里分析一下,泰山众筹模式的优势也就是它在市场爆火的原因。
|
JSON 区块链 数据格式
阿凡达泰山众筹系统开发(详细及程序)丨泰山众筹阿凡达系统开发(4.0运营版)
 We decided on reward and punishment measures,and then entered the agreement into the blockchain in the form of code.Once the agreed conditions are triggered,a program will automatically execute it,which is smart contract
|
Linux 内存技术
阿凡达模式Demo系统开发方案丨阿凡达泰山众筹系统开发
阿凡达模式Demo系统开发方案丨阿凡达泰山众筹系统开发
171 0
|
新零售 人工智能 缓存
泰山众筹(阿凡达4.0)系统开发详细及方案丨泰山众筹(阿凡达4.0)开发源码及平台
新零售是指个人、企业以互联网为依托,通过运用大数据、人工智能等先进技术手段并运用心理学知识,对商品的生产、流通与销售过程进行升级改造,进而重塑业态结构与生态圈,并对线上服务、线下体验以及现代物流进行深度融合的零售新模式。
|
新零售 存储 缓存
区块链阿凡达泰山众筹商城系统开发(正式版)丨区块链阿凡达泰山众筹商城开发源码系统
“新零售”的核心要义在于推动线上与线下的一体化进程,其关键在于使线上的互联网力量和线下的实体店终端形成真正意义上的合力,从而完成电商平台和实体零售店面在商业维度上的优化升级。同时,促成价格消费时代向价值消费时代的全面转型。
阿凡达(泰山众筹)开发原理丨阿凡达(泰山众筹)系统开发(详情开发)丨阿凡达及泰山众筹源码案例部署
交易是否能够结束的关键计算在SwapMath.computeSwapStep中完成,这里计算了交易是否能在目标价格范围内结束,以及消耗的tokenIn和得到的tokenOut.这里摘取此函数部分代码进行分析
|
区块链 数据格式 JSON
阿凡达Avatar泰山众筹开发说明,阿凡达Avatar泰山众筹系统开发技术分析,阿凡达Avatar泰山众筹源码稳定版
# 通过合约.功能.调用接口方法(传参数).获取返回值 # contract.functions.接口方法名(参数1,参数2,参数3).call() res = contract.functions.getLastMintInfo(10).call() print("getLastMintInfo:", res)
|
缓存
阿凡达泰山众筹商城开发详情丨阿凡达泰山众筹商城系统开发(开发模板)丨阿凡达泰山众筹商城源码及功能系统
 如果当前word中没有记录其他tick index,那么取这个word的最小/最大tick index,这么做的目的是,让单步交易中tick的跨度不至于太大,以减少计算中溢出的可能性
|
新零售 人工智能 前端开发
泰山众筹4.0阿凡达系统丨泰山众筹4.0阿凡达系统开发(上线版)丨泰山众筹4.0阿凡达开发源码平台
了解了线上电商和线下购物的短板,线上线下结合是新的销售通路,而这个新的销售通路就是新零售模式。在互联网工具快速发展的时期,要以互联网为依托,通过运用大数据、人工智能等先进技术手段,对商品的生产、流通与销售过程进行升级改造,进而重塑业态结构与生态圈,并对线上服务、线下体验以及现代物流进行深度融合,一是让商家生产消费者喜欢的商品,二是让消费者更容易找到自己喜欢的商品,实现线上考察、线下体验,线上线下购买。商家和消费者更有效的链接就是新零售模式。

热门文章

最新文章