//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(' ');
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';
//Create transaction
const txParams = {
nonce: web3.eth.getTransactionCount(userAccount),
from: userAccount,
gasPrice: '0x6FC23AC00',
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;
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
g++ -std=c++11 ip2str.cpp -o ip2str | |
ip2str 0xb01a8c0 0x100007f | |
*/ | |
#include <sstream> | |
#include <iostream> | |
using namespace std; | |
/* Simplest version */ |
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);
_;
}
Đ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
OlderNewer