//Generate seed from Math.random()
var seed = Math.random()*Math.pow(2,32);
//XorShift based PRNG
function rnd(){
var x = 0, i;
for(i = 0; i < 32; i++){
//Shift right if [i th] bit is equal to 1, otherwise shift letf
x ^= ((seed >> i) & 1) ? seed >> i : seed << i;
Our testor (Ms. Phương) talk to me about, duplication of passphrase will become invalid passphrase in our wallet.
Look at BIP39 there are no duplication check. So I give it a try.
Create bip39.js
var bip39 = require('bip39')
function scanDuplicated(value){
let buff = value.split(' ');
var BasicToken = artifacts.require('./BasicToken.sol');
const EthereumTx = require('../node_modules/ethereumjs-tx')
const userAccount = '0x5239d2bec5c8ee929ec27944cffc7b2667710b51';
//Create transaction
const txParams = {
nonce: web3.eth.getTransactionCount(userAccount),
from: userAccount,
gasPrice: '0x6FC23AC00',
pragma solidity ^0.4.11;
contract BasicToken {
mapping(address => uint256) balances;
function BasicToken(){
balances[address(0x005239d2bec5c8ee929ec27944cffc7b2667710b51)] = 1000;
}
var BasicToken = artifacts.require('./BasicToken.sol');
const EthereumTx = require('../node_modules/ethereumjs-tx')
const userAccount = '0x5239d2bec5c8ee929ec27944cffc7b2667710b51';
contract('BasicToken', function (accounts) {
Constructor will put 1000 token in account 0x5239d2bec5c8ee929ec27944cffc7b2667710b51
which was shown balances[address(0x005239d2bec5c8ee929ec27944cffc7b2667710b51)] = 1000;
Toàn bộ smart contract như sau
pragma solidity ^0.4.17;
contract PartTime {
struct Job {
uint256 id;
address creator;
uint256 salary;
Mình viết lại smart contract, thêm hai function mới takeJob()
và viewJob()
:
//Take job
function
takeJob (uint256 jobId)
public onlyValidMortgage(jobId) onlyValidId(jobId) onlyValidJob(jobId)
{
//Trigger event to log labor
TakeJob(jobId, msg.sender);
//Mapped data
mapping (uint256 => Job) public jobData;
//Transaction must contant Ethereum
modifier onlyHaveFund {
require(msg.value > MINIUM_SALARY);
_;
}
Kết quả khi mình chạy test, mình có dump data để các bạn có thể theo dõi sự thay đổi.
Contract: Partime
√ should have 0 total part time job
Job's details:
id: 0
creator: 0x4a8be21d76a3003bf62513907b3a460957086caf
salary: 1000000000000000000
start: 0
end: 0
Đoạn code bên dưới sẽ giúp Ethereum không bị trapped trong smart contract khi có người dùng vô tình gửi Ethereum vào.
//We don't let any trapped in this contract
function () public payable {
revert();
}
Từ Solidity 0.4.21
thì việc dùng constructor
sẽ thay thế cho việc sử dụng function có cùng tên với smart contract.
//Empty constructor