mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
Add test cases to shyft-clie/web3 and removed logs from consesnus.go and blockchain.go
This commit is contained in:
parent
d5e345a517
commit
ede486a68a
21 changed files with 6755 additions and 27 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -49,3 +49,5 @@ $HOME
|
|||
|
||||
# Remove Shyft Data
|
||||
shyftData/*
|
||||
shyft-cli/web3/token_test/node_modules
|
||||
shyft-cli/web3/transfer-through-master/node_modules
|
||||
|
|
|
|||
|
|
@ -565,6 +565,5 @@ func accumulateRewards(config *params.ChainConfig, state *state.StateDB, header
|
|||
|
||||
if (config.IsShyftNetwork(header.Number)) {
|
||||
state.AddBalance(ShyftNetworkConduitAddress, ShyftNetworkBlockReward)
|
||||
log.Info("ShyftNetwork")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,6 @@ type BlockChain struct {
|
|||
// available in the database. It initialises the default Ethereum Validator and
|
||||
// Processor.
|
||||
func NewBlockChain(db ethdb.Database, blockExplorerDb *sql.DB, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) {
|
||||
fmt.Printf("+++++++++++++++++core/blockchain.GO+++++++++++++++++++++++++NewBlockChain()")
|
||||
if cacheConfig == nil {
|
||||
cacheConfig = &CacheConfig{
|
||||
TrieNodeLimit: 256 * 1024 * 1024,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
// using contract from https://www.ethereum.org/greeter
|
||||
// compiled on remix
|
||||
|
||||
var _greeting = "Greeter Contract" ;
|
||||
var greeterContract = web3.eth.contract([{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"greet","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_greeting","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
|
||||
var greeter = greeterContract.new(
|
||||
_greeting,
|
||||
var _message = "Hello" ;
|
||||
var inboxContract = web3.eth.contract([{"constant":false,"inputs":[{"name":"_newMessage","type":"string"}],"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"message","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"_message","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_newMessage","type":"string"}],"name":"EventMessage","type":"event"}]);
|
||||
var inbox = inboxContract.new(
|
||||
_message,
|
||||
{
|
||||
from: web3.eth.accounts[0],
|
||||
data: '0x6060604052341561000f57600080fd5b6040516103a93803806103a983398101604052808051820191905050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060019080519060200190610081929190610088565b505061012d565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106100c957805160ff19168380011785556100f7565b828001600101855582156100f7579182015b828111156100f65782518255916020019190600101906100db565b5b5090506101049190610108565b5090565b61012a91905b8082111561012657600081600090555060010161010e565b5090565b90565b61026d8061013c6000396000f30060606040526004361061004c576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806341c0e1b514610051578063cfae321714610066575b600080fd5b341561005c57600080fd5b6100646100f4565b005b341561007157600080fd5b610079610185565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b957808201518184015260208101905061009e565b50505050905090810190601f1680156100e65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161415610183576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b61018d61022d565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156102235780601f106101f857610100808354040283529160200191610223565b820191906000526020600020905b81548152906001019060200180831161020657829003601f168201915b5050505050905090565b6020604051908101604052806000815250905600a165627a7a7230582015882dcaabcda0ebdb1b26a10e36f26a424e148671f4703dde3c1956ebaa67830029',
|
||||
data: '0x6060604052341561000f57600080fd5b604051610454380380610454833981016040528080518201919050508060009080519060200190610041929190610048565b50506100ed565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061008957805160ff19168380011785556100b7565b828001600101855582156100b7579182015b828111156100b657825182559160200191906001019061009b565b5b5090506100c491906100c8565b5090565b6100ea91905b808211156100e65760008160009055506001016100ce565b5090565b90565b610358806100fc6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063368b877214610048578063e21f37ce146100a557600080fd5b341561005357600080fd5b6100a3600480803590602001908201803590602001908080601f01602080910402602001604051908101604052809392919081815260200183838082843782019150505050505091905050610133565b005b34156100b057600080fd5b6100b86101e9565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100f85780820151818401526020810190506100dd565b50505050905090810190601f1680156101255780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b8060009080519060200190610149929190610287565b507f2ec385c52f10e65de137fbbeb2582bb0f4a8460a2163012971e923d179d73ea7816040518080602001828103825283818151815260200191508051906020019080838360005b838110156101ac578082015181840152602081019050610191565b50505050905090810190601f1680156101d95780820380516001836020036101000a031916815260200191505b509250505060405180910390a150565b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561027f5780601f106102545761010080835404028352916020019161027f565b820191906000526020600020905b81548152906001019060200180831161026257829003601f168201915b505050505081565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106102c857805160ff19168380011785556102f6565b828001600101855582156102f6579182015b828111156102f55782518255916020019190600101906102da565b5b5090506103039190610307565b5090565b61032991905b8082111561032557600081600090555060010161030d565b5090565b905600a165627a7a72305820c83fcf90975f9c6996cf8dde1a2a1f4fab1f408588a2f8587487833ac98665630029',
|
||||
gas: '4700000'
|
||||
}, function (e, contract){
|
||||
if(!e) {
|
||||
|
|
@ -21,7 +18,14 @@ var greeter = greeterContract.new(
|
|||
} else {
|
||||
console.log("Contract address:")
|
||||
console.log(contract.address) // the contract address
|
||||
contract.methods.setMessage('New').call({from: web3.eth.accounts[0]}, function(error, result){
|
||||
if (error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
console.log('[METHOD RESULT]: ', result)
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
|
|
|
|||
22
shyft-cli/web3/token_test/deployToken.js
Normal file
22
shyft-cli/web3/token_test/deployToken.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
var Web3 = require('web3')
|
||||
var web3 = new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:8545"));
|
||||
|
||||
var initialSupply = 1000000000000000
|
||||
var mytokenContract = web3.eth.contract([{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"_bool","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"initialSupply","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
|
||||
var mytoken = mytokenContract.new(
|
||||
initialSupply,
|
||||
{
|
||||
from: web3.eth.accounts[0],
|
||||
data: '0x6060604052341561000f57600080fd5b60405160208061032f83398101604052808051906020019091905050806000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002081905550506102b18061007e6000396000f30060606040526000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806370a0823114610048578063a9059cbb1461009557600080fd5b341561005357600080fd5b61007f600480803573ffffffffffffffffffffffffffffffffffffffff169060200190919050506100ef565b6040518082815260200191505060405180910390f35b34156100a057600080fd5b6100d5600480803573ffffffffffffffffffffffffffffffffffffffff16906020019091908035906020019091905050610107565b604051808215151515815260200191505060405180910390f35b60006020528060005260406000206000915090505481565b6000816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541015151561015657600080fd5b6000808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054826000808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205401101515156101e357600080fd5b816000803373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282540392505081905550816000808573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254019250508190555060019050929150505600a165627a7a723058207dba9cbbfe34ea34b40caa5e6d2b53f9194dafa2420207342bebe3a5c949840c0029',
|
||||
gas: '4700000'
|
||||
}, function (e, contract) {
|
||||
if (e) console.log("err1", e);
|
||||
if (typeof contract.address !== 'undefined') {
|
||||
console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
|
||||
var a = mytokenContract.at(contract.address);
|
||||
a.transfer.sendTransaction(web3.eth.accounts[0], 5000000, {from: web3.eth.accounts[0]}, function (err, res) {
|
||||
if (err) console.log("err", err);
|
||||
console.log(res)
|
||||
})
|
||||
}
|
||||
});
|
||||
22
shyft-cli/web3/token_test/multi.js
Normal file
22
shyft-cli/web3/token_test/multi.js
Normal file
File diff suppressed because one or more lines are too long
43
shyft-cli/web3/token_test/package-lock.json
generated
Normal file
43
shyft-cli/web3/token_test/package-lock.json
generated
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"name": "token_contract",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"bignumber.js": {
|
||||
"version": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934"
|
||||
},
|
||||
"crypto-js": {
|
||||
"version": "3.1.8",
|
||||
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.8.tgz",
|
||||
"integrity": "sha1-cV8HC/YBTyrpkqmLOSkli3E/CNU="
|
||||
},
|
||||
"utf8": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
|
||||
"integrity": "sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY="
|
||||
},
|
||||
"web3": {
|
||||
"version": "0.20.6",
|
||||
"resolved": "https://registry.npmjs.org/web3/-/web3-0.20.6.tgz",
|
||||
"integrity": "sha1-PpcwauAk+yThCj11yIQwJWIhUSA=",
|
||||
"requires": {
|
||||
"bignumber.js": "git+https://github.com/frozeman/bignumber.js-nolookahead.git#57692b3ecfc98bbdd6b3a516cb2353652ea49934",
|
||||
"crypto-js": "3.1.8",
|
||||
"utf8": "2.1.2",
|
||||
"xhr2": "0.1.4",
|
||||
"xmlhttprequest": "1.8.0"
|
||||
}
|
||||
},
|
||||
"xhr2": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/xhr2/-/xhr2-0.1.4.tgz",
|
||||
"integrity": "sha1-f4dliEdxbbUCYyOBL4GMras4el8="
|
||||
},
|
||||
"xmlhttprequest": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/xmlhttprequest/-/xmlhttprequest-1.8.0.tgz",
|
||||
"integrity": "sha1-Z/4HXFwk/vOfnWX197f+dRcZaPw="
|
||||
}
|
||||
}
|
||||
}
|
||||
1393
shyft-cli/web3/transfer-through-master/build/contracts/Migrations.json
Executable file
1393
shyft-cli/web3/transfer-through-master/build/contracts/Migrations.json
Executable file
File diff suppressed because it is too large
Load diff
4652
shyft-cli/web3/transfer-through-master/build/contracts/Transfers.json
Executable file
4652
shyft-cli/web3/transfer-through-master/build/contracts/Transfers.json
Executable file
File diff suppressed because it is too large
Load diff
423
shyft-cli/web3/transfer-through-master/build/contracts/Transfers2.json
Executable file
423
shyft-cli/web3/transfer-through-master/build/contracts/Transfers2.json
Executable file
|
|
@ -0,0 +1,423 @@
|
|||
{
|
||||
"contractName": "Transfers2",
|
||||
"abi": [
|
||||
{
|
||||
"constant": false,
|
||||
"inputs": [
|
||||
{
|
||||
"name": "_addr",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [],
|
||||
"payable": true,
|
||||
"stateMutability": "payable",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x608060405234801561001057600080fd5b5060ed8061001f6000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631a695230146044575b600080fd5b6076600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506078565b005b8073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f1935050505015801560bd573d6000803e3d6000fd5b50505600a165627a7a72305820e95f74106a3328ffadd8b0adb916d92497daab65998ee73cf40afff57dc4b29b0029",
|
||||
"deployedBytecode": "0x608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680631a695230146044575b600080fd5b6076600480360381019080803573ffffffffffffffffffffffffffffffffffffffff1690602001909291905050506078565b005b8073ffffffffffffffffffffffffffffffffffffffff166108fc349081150290604051600060405180830381858888f1935050505015801560bd573d6000803e3d6000fd5b50505600a165627a7a72305820e95f74106a3328ffadd8b0adb916d92497daab65998ee73cf40afff57dc4b29b0029",
|
||||
"sourceMap": "26:106:2:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;26:106:2;;;;;;;",
|
||||
"deployedSourceMap": "26:106:2:-;;;;;;;;;;;;;;;;;;;;;;;;49:81;;;;;;;;;;;;;;;;;;;;;;;;;;;;;101:5;:14;;:25;116:9;101:25;;;;;;;;;;;;;;;;;;;;;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;101:25:2;49:81;:::o",
|
||||
"source": "pragma solidity ^0.4.19;\n\ncontract Transfers2 {\n\tfunction transfer(address _addr) public payable {\n\t\t_addr.transfer(msg.value);\n\t}\n}",
|
||||
"sourcePath": "/Users/gregmarkou/Jobs/Jobs/ChainSafe/shyftNetwork/shyft_go-ethereum/shyft-cli/web3/transfer-through-master/contracts/Transfers2.sol",
|
||||
"ast": {
|
||||
"absolutePath": "/Users/gregmarkou/Jobs/Jobs/ChainSafe/shyftNetwork/shyft_go-ethereum/shyft-cli/web3/transfer-through-master/contracts/Transfers2.sol",
|
||||
"exportedSymbols": {
|
||||
"Transfers2": [
|
||||
249
|
||||
]
|
||||
},
|
||||
"id": 250,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 235,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"^",
|
||||
"0.4",
|
||||
".19"
|
||||
],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:24:2"
|
||||
},
|
||||
{
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 249,
|
||||
"linearizedBaseContracts": [
|
||||
249
|
||||
],
|
||||
"name": "Transfers2",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
{
|
||||
"body": {
|
||||
"id": 247,
|
||||
"nodeType": "Block",
|
||||
"src": "97:33:2",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"arguments": [
|
||||
{
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 243,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 264,
|
||||
"src": "116:3:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 244,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "value",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "116:9:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": [
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 240,
|
||||
"name": "_addr",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 237,
|
||||
"src": "101:5:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"id": 242,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "transfer",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "101:14:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_function_transfer_nonpayable$_t_uint256_$returns$__$",
|
||||
"typeString": "function (uint256)"
|
||||
}
|
||||
},
|
||||
"id": 245,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"kind": "functionCall",
|
||||
"lValueRequested": false,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "101:25:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_tuple$__$",
|
||||
"typeString": "tuple()"
|
||||
}
|
||||
},
|
||||
"id": 246,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "101:25:2"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 248,
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"isDeclaredConst": false,
|
||||
"modifiers": [],
|
||||
"name": "transfer",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters": {
|
||||
"id": 238,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [
|
||||
{
|
||||
"constant": false,
|
||||
"id": 237,
|
||||
"name": "_addr",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 248,
|
||||
"src": "67:13:2",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"typeName": {
|
||||
"id": 236,
|
||||
"name": "address",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "67:7:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"src": "66:15:2"
|
||||
},
|
||||
"payable": true,
|
||||
"returnParameters": {
|
||||
"id": 239,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "97:0:2"
|
||||
},
|
||||
"scope": 249,
|
||||
"src": "49:81:2",
|
||||
"stateMutability": "payable",
|
||||
"superFunction": null,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 250,
|
||||
"src": "26:106:2"
|
||||
}
|
||||
],
|
||||
"src": "0:132:2"
|
||||
},
|
||||
"legacyAST": {
|
||||
"absolutePath": "/Users/gregmarkou/Jobs/Jobs/ChainSafe/shyftNetwork/shyft_go-ethereum/shyft-cli/web3/transfer-through-master/contracts/Transfers2.sol",
|
||||
"exportedSymbols": {
|
||||
"Transfers2": [
|
||||
249
|
||||
]
|
||||
},
|
||||
"id": 250,
|
||||
"nodeType": "SourceUnit",
|
||||
"nodes": [
|
||||
{
|
||||
"id": 235,
|
||||
"literals": [
|
||||
"solidity",
|
||||
"^",
|
||||
"0.4",
|
||||
".19"
|
||||
],
|
||||
"nodeType": "PragmaDirective",
|
||||
"src": "0:24:2"
|
||||
},
|
||||
{
|
||||
"baseContracts": [],
|
||||
"contractDependencies": [],
|
||||
"contractKind": "contract",
|
||||
"documentation": null,
|
||||
"fullyImplemented": true,
|
||||
"id": 249,
|
||||
"linearizedBaseContracts": [
|
||||
249
|
||||
],
|
||||
"name": "Transfers2",
|
||||
"nodeType": "ContractDefinition",
|
||||
"nodes": [
|
||||
{
|
||||
"body": {
|
||||
"id": 247,
|
||||
"nodeType": "Block",
|
||||
"src": "97:33:2",
|
||||
"statements": [
|
||||
{
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"arguments": [
|
||||
{
|
||||
"argumentTypes": null,
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 243,
|
||||
"name": "msg",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 264,
|
||||
"src": "116:3:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_magic_message",
|
||||
"typeString": "msg"
|
||||
}
|
||||
},
|
||||
"id": 244,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "value",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "116:9:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": [
|
||||
{
|
||||
"typeIdentifier": "t_uint256",
|
||||
"typeString": "uint256"
|
||||
}
|
||||
],
|
||||
"expression": {
|
||||
"argumentTypes": null,
|
||||
"id": 240,
|
||||
"name": "_addr",
|
||||
"nodeType": "Identifier",
|
||||
"overloadedDeclarations": [],
|
||||
"referencedDeclaration": 237,
|
||||
"src": "101:5:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"id": 242,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"lValueRequested": false,
|
||||
"memberName": "transfer",
|
||||
"nodeType": "MemberAccess",
|
||||
"referencedDeclaration": null,
|
||||
"src": "101:14:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_function_transfer_nonpayable$_t_uint256_$returns$__$",
|
||||
"typeString": "function (uint256)"
|
||||
}
|
||||
},
|
||||
"id": 245,
|
||||
"isConstant": false,
|
||||
"isLValue": false,
|
||||
"isPure": false,
|
||||
"kind": "functionCall",
|
||||
"lValueRequested": false,
|
||||
"names": [],
|
||||
"nodeType": "FunctionCall",
|
||||
"src": "101:25:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_tuple$__$",
|
||||
"typeString": "tuple()"
|
||||
}
|
||||
},
|
||||
"id": 246,
|
||||
"nodeType": "ExpressionStatement",
|
||||
"src": "101:25:2"
|
||||
}
|
||||
]
|
||||
},
|
||||
"documentation": null,
|
||||
"id": 248,
|
||||
"implemented": true,
|
||||
"isConstructor": false,
|
||||
"isDeclaredConst": false,
|
||||
"modifiers": [],
|
||||
"name": "transfer",
|
||||
"nodeType": "FunctionDefinition",
|
||||
"parameters": {
|
||||
"id": 238,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [
|
||||
{
|
||||
"constant": false,
|
||||
"id": 237,
|
||||
"name": "_addr",
|
||||
"nodeType": "VariableDeclaration",
|
||||
"scope": 248,
|
||||
"src": "67:13:2",
|
||||
"stateVariable": false,
|
||||
"storageLocation": "default",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
},
|
||||
"typeName": {
|
||||
"id": 236,
|
||||
"name": "address",
|
||||
"nodeType": "ElementaryTypeName",
|
||||
"src": "67:7:2",
|
||||
"typeDescriptions": {
|
||||
"typeIdentifier": "t_address",
|
||||
"typeString": "address"
|
||||
}
|
||||
},
|
||||
"value": null,
|
||||
"visibility": "internal"
|
||||
}
|
||||
],
|
||||
"src": "66:15:2"
|
||||
},
|
||||
"payable": true,
|
||||
"returnParameters": {
|
||||
"id": 239,
|
||||
"nodeType": "ParameterList",
|
||||
"parameters": [],
|
||||
"src": "97:0:2"
|
||||
},
|
||||
"scope": 249,
|
||||
"src": "49:81:2",
|
||||
"stateMutability": "payable",
|
||||
"superFunction": null,
|
||||
"visibility": "public"
|
||||
}
|
||||
],
|
||||
"scope": 250,
|
||||
"src": "26:106:2"
|
||||
}
|
||||
],
|
||||
"src": "0:132:2"
|
||||
},
|
||||
"compiler": {
|
||||
"name": "solc",
|
||||
"version": "0.4.24+commit.e67f0147.Emscripten.clang"
|
||||
},
|
||||
"networks": {
|
||||
"1": {
|
||||
"events": {},
|
||||
"links": {},
|
||||
"address": "0xa863f8203ad95e9078f6300e7857a4cca4fb4c60",
|
||||
"transactionHash": "0xb836110657221cb8ac728c0345ae03da1cb4313cfa0bb61285f31b780907af50"
|
||||
},
|
||||
"1528420224459": {
|
||||
"events": {},
|
||||
"links": {},
|
||||
"address": "0x411410538c50b116663acd654e34dc6bed601cf0",
|
||||
"transactionHash": "0x43f3fed1df72adfe12dd0c2432f0625b4b50b0c151f9583a166722ed74786ce3"
|
||||
}
|
||||
},
|
||||
"schemaVersion": "2.0.0",
|
||||
"updatedAt": "2018-06-08T15:58:27.899Z"
|
||||
}
|
||||
23
shyft-cli/web3/transfer-through-master/contracts/Migrations.sol
Executable file
23
shyft-cli/web3/transfer-through-master/contracts/Migrations.sol
Executable file
|
|
@ -0,0 +1,23 @@
|
|||
pragma solidity ^0.4.23;
|
||||
|
||||
contract Migrations {
|
||||
address public owner;
|
||||
uint public last_completed_migration;
|
||||
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
modifier restricted() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function setCompleted(uint completed) public restricted {
|
||||
last_completed_migration = completed;
|
||||
}
|
||||
|
||||
function upgrade(address new_address) public restricted {
|
||||
Migrations upgraded = Migrations(new_address);
|
||||
upgraded.setCompleted(last_completed_migration);
|
||||
}
|
||||
}
|
||||
44
shyft-cli/web3/transfer-through-master/contracts/Transfers.sol
Executable file
44
shyft-cli/web3/transfer-through-master/contracts/Transfers.sol
Executable file
|
|
@ -0,0 +1,44 @@
|
|||
pragma solidity ^0.4.19;
|
||||
|
||||
import "./Transfers2.sol";
|
||||
|
||||
contract Transfers {
|
||||
mapping (address => uint) public balance;
|
||||
Transfers2 t;
|
||||
address t_addr;
|
||||
|
||||
constructor() public {
|
||||
t = new Transfers2();
|
||||
t_addr = address(t);
|
||||
}
|
||||
|
||||
function transfer(address _addr, uint _value) public {
|
||||
require(balance[msg.sender] >= _value);
|
||||
bytes4 sig = bytes4(keccak256("transfer(address)"));
|
||||
t_addr.call.value(_value)(sig, _addr);
|
||||
}
|
||||
|
||||
function myBalance() public returns (uint) {
|
||||
return balance[msg.sender];
|
||||
}
|
||||
|
||||
function deposit() public payable returns (uint) {
|
||||
balance[msg.sender] += msg.value;
|
||||
return balance[msg.sender];
|
||||
}
|
||||
|
||||
function withdraw(address _addr, uint _value) public {
|
||||
require(balance[msg.sender] >= _value);
|
||||
balance[msg.sender] -= _value;
|
||||
_addr.transfer(_value);
|
||||
}
|
||||
|
||||
function withdrawMulti(address[] _addrs, uint _value) public {
|
||||
uint l = _addrs.length;
|
||||
require(balance[msg.sender] >= _value * l);
|
||||
balance[msg.sender] -= _value * l;
|
||||
for (uint i = 0; i < l; i++){
|
||||
_addrs[i].transfer(_value);
|
||||
}
|
||||
}
|
||||
}
|
||||
7
shyft-cli/web3/transfer-through-master/contracts/Transfers2.sol
Executable file
7
shyft-cli/web3/transfer-through-master/contracts/Transfers2.sol
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
pragma solidity ^0.4.19;
|
||||
|
||||
contract Transfers2 {
|
||||
function transfer(address _addr) public payable {
|
||||
_addr.transfer(msg.value);
|
||||
}
|
||||
}
|
||||
5
shyft-cli/web3/transfer-through-master/migrations/1_initial_migration.js
Executable file
5
shyft-cli/web3/transfer-through-master/migrations/1_initial_migration.js
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
var Migrations = artifacts.require("./Migrations.sol");
|
||||
|
||||
module.exports = function(deployer) {
|
||||
deployer.deploy(Migrations);
|
||||
};
|
||||
7
shyft-cli/web3/transfer-through-master/migrations/2_migrate.js
Executable file
7
shyft-cli/web3/transfer-through-master/migrations/2_migrate.js
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
var Transfers = artifacts.require('./Transfers.sol')
|
||||
var Transfers2 = artifacts.require('./Transfers2.sol')
|
||||
|
||||
module.exports = function (deployer) {
|
||||
deployer.deploy(Transfers)
|
||||
deployer.deploy(Transfers2)
|
||||
}
|
||||
5
shyft-cli/web3/transfer-through-master/package-lock.json
generated
Executable file
5
shyft-cli/web3/transfer-through-master/package-lock.json
generated
Executable file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "transfers",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1
|
||||
}
|
||||
15
shyft-cli/web3/transfer-through-master/package.json
Executable file
15
shyft-cli/web3/transfer-through-master/package.json
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"name": "transfers",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "truffle-config.js",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC"
|
||||
}
|
||||
41
shyft-cli/web3/transfer-through-master/test/test.js
Executable file
41
shyft-cli/web3/transfer-through-master/test/test.js
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
var Transfers = artifacts.require("Transfers");
|
||||
var Transfers2 = artifacts.require("Transfers2");
|
||||
|
||||
contract('Transfers', function(accounts) {
|
||||
var addressA = web3.eth.accounts[0];
|
||||
var addressB = web3.eth.accounts[1];
|
||||
var transfers;
|
||||
web3.eth.defaultAccount = web3.eth.accounts[0];
|
||||
|
||||
it("should initialize", async() => {
|
||||
transfers = await Transfers.new();
|
||||
transfers2 = await Transfers2.new();
|
||||
assert(transfers !== undefined, "");
|
||||
assert(transfers2 !== undefined, "");
|
||||
})
|
||||
|
||||
it("should deposit", async() => {
|
||||
let hash = await transfers.deposit({from: addressA, value: web3.toWei(4, "ether")});
|
||||
let bal = await transfers.deposit.call({from: addressA});
|
||||
console.log("\t\t[DEPOSIT TX]", hash.tx)
|
||||
//console.log(bal);
|
||||
})
|
||||
|
||||
it("should withdraw", async() => {
|
||||
let prevB = await web3.eth.getBalance(addressB);
|
||||
let hash = await transfers.withdraw(addressB, web3.toWei(1, "ether"), {from: addressA});
|
||||
let postB = await web3.eth.getBalance(addressB);
|
||||
console.log("\t\t[WITHDRAW TX]", hash.tx)
|
||||
//assert(postB - prevB == val, "");
|
||||
})
|
||||
|
||||
it("should transfer through other contract", async() => {
|
||||
let val = 10;
|
||||
let prevB = await web3.eth.getBalance(addressB);
|
||||
|
||||
let hash = await transfers.transfer(addressB, web3.toWei(1, "ether"), {from: addressA});
|
||||
let postB = await web3.eth.getBalance(addressB);
|
||||
console.log("\t\t[TRANSFER THROUGH TX]", hash.tx)
|
||||
// assert(web3.fromWei(prevB,'wei') - web3.fromWei(postB,'wei') == val, "");
|
||||
})
|
||||
})
|
||||
12
shyft-cli/web3/transfer-through-master/truffle-config.js
Executable file
12
shyft-cli/web3/transfer-through-master/truffle-config.js
Executable file
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
// See <http://truffleframework.com/docs/advanced/configuration>
|
||||
// to customize your Truffle configuration!
|
||||
|
||||
networks: {
|
||||
geth_testnet: {
|
||||
host: "127.0.0.1",
|
||||
port: 8545,
|
||||
netword_id: "*"
|
||||
}
|
||||
}
|
||||
};
|
||||
10
shyft-cli/web3/transfer-through-master/truffle.js
Executable file
10
shyft-cli/web3/transfer-through-master/truffle.js
Executable file
|
|
@ -0,0 +1,10 @@
|
|||
module.exports = {
|
||||
networks: {
|
||||
development: {
|
||||
host: 'localhost',
|
||||
port: 8545,
|
||||
network_id: '*',
|
||||
//gasLimit: 6.7e6
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Reference in a new issue