Exemplo n.º 1
0
// Creates a 20 byte address and bumps the creator's nonce.
func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account {

	// Generate an address
	nonce := creator.Nonce
	creator.Nonce += 1

	addr := LeftPadWord256(NewContractAddress(creator.Address.Postfix(20), int(nonce)))

	// Create account from address.
	account, removed := vmUnpack(cache.accounts[addr])
	if removed || account == nil {
		account = &vm.Account{
			Address:     addr,
			Balance:     0,
			Code:        nil,
			Nonce:       0,
			StorageRoot: Zero256,
			Permissions: cache.GetAccount(ptypes.GlobalPermissionsAddress256).Permissions,
			Other:       nil,
		}
		cache.accounts[addr] = vmAccountInfo{account, false}
		return account
	} else {
		// NONCE HANDLING SANITY CHECK OR SHA3 IS BROKEN
		panic(Fmt("Could not create account, address already exists: %X", addr))
	}
}
Exemplo n.º 2
0
// Creates a 20 byte address and bumps the creator's nonce.
func (cache *TxCache) CreateAccount(creator *vm.Account) *vm.Account {

	// Generate an address
	nonce := creator.Nonce
	creator.Nonce += 1

	addr := LeftPadWord256(NewContractAddress(creator.Address.Postfix(20), int(nonce)))

	// Create account from address.
	account, removed := cache.accounts[addr].unpack()
	if removed || account == nil {
		account = &vm.Account{
			Address:     addr,
			Balance:     0,
			Code:        nil,
			Nonce:       0,
			Permissions: cache.GetAccount(ptypes.GlobalPermissionsAddress256).Permissions,
			Other: vmAccountOther{
				PubKey:      nil,
				StorageRoot: nil,
			},
		}
		cache.accounts[addr] = vmAccountInfo{account, false}
		return account
	} else {
		// either we've messed up nonce handling, or sha3 is broken
		PanicSanity(Fmt("Could not create account, address already exists: %X", addr))
		return nil
	}
}