Beispiel #1
0
pair<h256, Address> MixClient::submitTransaction(eth::TransactionSkeleton const& _ts, Secret const& _secret, bool _gasAuto)
{
	WriteGuard l(x_state);
	TransactionSkeleton ts = _ts;
	ts.from = toAddress(_secret);
	ts.nonce = m_postMine.transactionsFrom(ts.from);
	eth::Transaction t(ts, _secret);
	executeTransaction(t, m_postMine, false, _gasAuto, _secret);
	return make_pair(t.sha3(), toAddress(ts.from, ts.nonce));
}
Beispiel #2
0
Json::Value toJson(dev::eth::TransactionReceipt const& _tr, std::pair<h256, unsigned> _location, BlockNumber _blockNumber, Transaction const& _t)
{
    Json::Value res;
    h256 h = _t.sha3();
    res["transactionHash"] = toJS(h);
    res["transactionIndex"] = _location.second;
    res["blockHash"] = toJS(_location.first);
    res["blockNumber"] = _blockNumber;
    res["cumulativeGasUsed"] = toJS(_tr.gasUsed()); // TODO: check if this is fine
    res["gasUsed"] = toJS(_tr.gasUsed());
    res["contractAddress"] = toJS(toAddress(_t.from(), _t.nonce()));
    res["logs"] = Json::Value(Json::arrayValue);
    for (unsigned i = 0; i < _tr.log().size(); i++)
    {
        LogEntry e = _tr.log()[i];
        Json::Value l = toJson(e);
        l["type"] = "mined";
        l["blockNumber"] = _blockNumber;
        l["blockHash"] = toJS(_location.first);
        l["logIndex"] = i;
        l["transactionHash"] = toJS(h);
        l["transactionIndex"] = _location.second;
        res["logs"].append(l);
    }
    return res;
}
Beispiel #3
0
void MixClient::submitTransaction(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, bool _gasAuto)
{
	WriteGuard l(x_state);
	u256 n = m_state.transactionsFrom(toAddress(_secret));
	Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);
	executeTransaction(t, m_state, false, _gasAuto, _secret);
}
Beispiel #4
0
Address MixClient::submitTransaction(Secret _secret, u256 _endowment, bytes const& _init, u256 _gas, u256 _gasPrice, bool _gasAuto)
{
	WriteGuard l(x_state);
	u256 n = m_state.transactionsFrom(toAddress(_secret));
	eth::Transaction t(_endowment, _gasPrice, _gas, _init, n, _secret);
	executeTransaction(t, m_state, false, _gasAuto, _secret);
	Address address = right160(sha3(rlpList(t.sender(), t.nonce())));
	return address;
}
Beispiel #5
0
/* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
static int Address__gc(lua_State* L) {
    Address addr = toAddress(L,1);

    if (addr) {
        g_free((void*)(addr->data));
        g_free((void*)(addr));
    }

    return 0;
}
Beispiel #6
0
dev::eth::ExecutionResult MixClient::call(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice, BlockNumber _blockNumber, bool _gasAuto, FudgeFactor _ff)
{
	(void)_blockNumber;
	Address a = toAddress(_secret);
	State temp = asOf(eth::PendingBlock);
	u256 n = temp.transactionsFrom(a);
	Transaction t(_value, _gasPrice, _gas, _dest, _data, n, _secret);
	if (_ff == FudgeFactor::Lenient)
		temp.addBalance(a, (u256)(t.gasRequired() * t.gasPrice() + t.value()));
	bytes rlp = t.rlp();
	WriteGuard lw(x_state); //TODO: lock is required only for last execution state
	executeTransaction(t, temp, true, _gasAuto, _secret);
	return lastExecution().result;
}
/*!-----------------------------------------------------------------------

    s m _ i n i t i a l i z e

    @brief Initialize the data structures in a new shared memory segment.

    The specified file (referenced by the supplied file descriptor) will be
    mapped into virtual memory and the size of the file adjusted to match the
    desired size of the shared memory segment.

    This function will set up all of the data structures in the shared memory
    segment for use.  This function should be called after a brand new shared
    memory segment has been created and opened on disk.  This function should
    not be called on an existing shared memory segment that contains data as
    all of that data will be deleted by this function.

    @param[in] fd - The file descriptor of the file associated with this
               shared memory segment.

    @param[in] sharedMemorySegmentSize - The size of the shared memory
               segment in bytes.

    @return The new memory address of where the shared memory segment begins.
            On error, a null pointer is returned and errno will be set to
            indicate the error that was encountered.

------------------------------------------------------------------------*/
sharedMemory_t* sm_initialize ( int fd, size_t sharedMemorySegmentSize )
{
    int             status;
    sharedMemory_t* sharedMemory;

    LOG ( "Initializing user shared memory - fd[%d], Size[%'lu]\n", fd,
          sharedMemorySegmentSize );
    //
    //  Map the shared memory file into virtual memory.
    //
    sharedMemory = mmap ( NULL, INITIAL_SHARED_MEMORY_SIZE,
                          PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0 );
    if ( sharedMemory == MAP_FAILED )
    {
        printf ( "Unable to map the user shared memory segment. errno: %u[%m].\n",
                 errno );
        return 0;
    }
    //
    //  Make the pseudo-file for the shared memory segment the size of the
    //  shared memory segment.  Note that this will destroy any existing data
    //  if the segment already exists.
    //
    status = ftruncate ( fd, INITIAL_SHARED_MEMORY_SIZE );
    if (status != 0)
    {
        printf ( "Unable to resize the user shared memory segment to [%'lu] bytes - "
                 "errno: %u[%m].\n", INITIAL_SHARED_MEMORY_SIZE, errno );
        return 0;
    }
    //
    //  Set all of the data in this shared memory segment to zero.
    //
    // TODO: (void)memset ( sharedMemory, 0, sharedMemorySegmentSize );
    (void)memset ( sharedMemory, 0xaa, sharedMemorySegmentSize );

    //
    //  Initialize our global pointer to the shared memory segment.
    //
    smControl = sharedMemory;

    //
    //  Initialize the fields in the shared memory control structure.  This
    //  structure is located at the beginning of the shared memory region that
    //  we just created and the fields here are adjusted to take into account
    //  the size of the user shared memory structure.
    //
    smControl->sharedMemorySegmentSize = sharedMemorySegmentSize;
    smControl->currentOffset           = smSize;
    smControl->currentSize             = sharedMemorySegmentSize - smSize;
    smControl->systemInitialized       = 0;

    //
    //  Create the mutex attribute initializer that we can use to initialize
    //  all of the mutexes in the B-trees.
    //
    pthread_mutexattr_t* mutexAttributes = &smControl->masterMutexAttributes;

    status =  pthread_mutexattr_init ( mutexAttributes );
    if ( status != 0 )
    {
        printf ( "Unable to initialize mutex attributes - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    // Set this mutex to be a process shared mutex.
    //
    status = pthread_mutexattr_setpshared ( mutexAttributes,
                                            PTHREAD_PROCESS_SHARED );
    if ( status != 0 )
    {
        printf ( "Unable to set shared mutex attribute - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    // Set this mutex to be a recursive mutex.
    //
    status = pthread_mutexattr_settype ( mutexAttributes,
                                         PTHREAD_MUTEX_RECURSIVE );
    if ( status != 0 )
    {
        printf ( "Unable to set recursive mutex attribute - errno: %u[%m].\n",
                 status );
        return 0;
    }
    //
    //  Create the condition variable initializer that we can use to
    //  initialize all of the condition variables in the shared memory
    //  segment.
    //
    pthread_condattr_t* conditionVariableAttributes =
        &smControl->masterCvAttributes;

    status = pthread_condattr_init ( conditionVariableAttributes );

    if ( status != 0 )
    {
        printf ( "Unable to initialize condition variable attributes - "
                 "errno: %u[%m].\n", status );
        return 0;
    }
    //
    //  Set this condition variable to be shared between processes.
    //
    status = pthread_condattr_setpshared ( conditionVariableAttributes,
                                           PTHREAD_PROCESS_SHARED );
    if ( status != 0 )
    {
        printf ( "Unable to set shared condition variable attributes - "
                 "errno: %u[%m].\n", status );
        return 0;
    }
    //
    //  Initialize the shared memory mutex.
    //
    status = pthread_mutex_init ( &smControl->smLock, mutexAttributes );
    if ( status != 0 )
    {
        printf ( "Unable to initialize shared memory manager mutex - errno: "
                 "%u[%m].\n", status );
        return 0;
    }
    //
    //  Now put the rest of the preallocated memory into the free memory pool.
    //
    //  Define the memory chunk data structure at the beginning of the free
    //  section of memory and initialize it.
    //
    memoryChunk_t* availableMemory = toAddress ( smControl->currentOffset );

    availableMemory->marker      = SM_FREE_MARKER;
    availableMemory->segmentSize = smControl->currentSize;
    availableMemory->offset      = smControl->currentOffset;
    availableMemory->type        = TYPE_USER;

    //
    //  Go insert this memory into the shared memory allocation B-trees.
    //
    (void)insertMemoryChunk ( availableMemory );

    //
    //  Set the "initialized" flag to indicate that the shared memory
    //  allocation system is in a usable state.  Note that this indicator is
    //  primarily used by the sm_malloc function to determine how to allocate
    //  memory for the shared memory memory management function B-trees that
    //  we just defined above.
    //
    smControl->systemInitialized = 1;

    //
    //  Let the user know that the system initialization has been completed.
    //
    LOG ( "\n===== User shared memory is Initialized at %p =====\n\n",
          smControl );

#ifdef VSI_DEBUG
    dumpSM();
#endif

    //
    //  Return the address of the shared memory segment to the caller.
    //
    return smControl;
}
/**
   Create a UDP socket. Perform a zero-length SendTo, then attempt to receive the zero-length datagram.

   @return EPass on success, EFail on failure
*/
TVerdict CEsockTest9_6::easyTestStepL()
	{
	Logger().WriteFormat(_L("TE_ESock: test 9.6"));
	
	TInt cleanupCount = 0;		// Number of items we've put on Cleanup Stack - remember to increment this after every Push operation.
	
	RSocket sendSocket;

	CleanupClosePushL( sendSocket );
	++cleanupCount;

	TSockAddr sendSocketAddress;
	Logger().WriteFormat(_L("Creating Send Socket"));
	if( !CreateUdpSocket( sendSocket, sendSocketAddress ) )
		{
		CleanupStack::PopAndDestroy( cleanupCount );
		return EFail;
		}


	RSocket recvSocket;

	CleanupClosePushL( recvSocket );
	++cleanupCount;

	TSockAddr recvSocketAddress;
	Logger().WriteFormat(_L("Creating Receive Socket"));
	if( !CreateUdpSocket( recvSocket, recvSocketAddress ) )
		{
		CleanupStack::PopAndDestroy( cleanupCount );
		return EFail;
		}



	HBufC8 *udpWriteBuffer = HBufC8::NewLC( 0 ); // Empty buffer for zero-length write
	++cleanupCount;

	HBufC8 *udpReadBuffer  = HBufC8::NewMaxLC( 32 ); // Non-Empty buffer for reads - 32 is an unimportant magic number
	++cleanupCount;

	TPtrC8  ptrWritebuf( udpWriteBuffer->Des() );
	TPtr8   ptrReadbuf( udpReadBuffer->Des() );
	TSockAddr toAddress( recvSocketAddress );

	TBool isOk = PerformSend( sendSocket, ptrWritebuf, toAddress );
	if( isOk )
		{
		TSockAddr fromAddress;
		isOk = PerformRecv( recvSocket, ptrReadbuf, fromAddress );
		if( isOk )
			{
			Logger().WriteFormat(_L("Receieved %d bytes"), udpReadBuffer->Length());
			if( udpReadBuffer->Length() != 0 )
				{
				isOk = EFalse;
				}
			}
		}
	
	CleanupStack::PopAndDestroy( cleanupCount );

	return isOk ? EPass : EFail;
	}