|
|
@ -230,6 +230,12 @@ func (c *crossShardXferPrecompile) RunWriteCapable( |
|
|
|
contract *Contract, |
|
|
|
contract *Contract, |
|
|
|
input []byte, |
|
|
|
input []byte, |
|
|
|
) ([]byte, error) { |
|
|
|
) ([]byte, error) { |
|
|
|
|
|
|
|
// make sure that cxReceipt is already nil to
|
|
|
|
|
|
|
|
// prevent multiple calls to the precompile
|
|
|
|
|
|
|
|
// in the same transaction
|
|
|
|
|
|
|
|
if evm.CXReceipt != nil { |
|
|
|
|
|
|
|
return nil, errors.New("cannot call cross shard precompile again in same tx") |
|
|
|
|
|
|
|
} |
|
|
|
fromAddress, toAddress, fromShardID, toShardID, value, err := |
|
|
|
fromAddress, toAddress, fromShardID, toShardID, value, err := |
|
|
|
parseCrossShardXferData(evm, contract, input) |
|
|
|
parseCrossShardXferData(evm, contract, input) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -257,22 +263,16 @@ func (c *crossShardXferPrecompile) RunWriteCapable( |
|
|
|
return nil, errors.New("not enough balance received") |
|
|
|
return nil, errors.New("not enough balance received") |
|
|
|
} |
|
|
|
} |
|
|
|
evm.Transfer(evm.StateDB, contract.Address(), toAddress, value, types.SubtractionOnly) |
|
|
|
evm.Transfer(evm.StateDB, contract.Address(), toAddress, value, types.SubtractionOnly) |
|
|
|
// make sure that cxreceipt is already nil to prevent multiple calls to the precompile
|
|
|
|
// step 2 -> make a cross link
|
|
|
|
// in the same transaction
|
|
|
|
// note that the transaction hash is added by state_processor.go to this receipt
|
|
|
|
if evm.CXReceipt == nil { |
|
|
|
// and that the receiving shard does not care about the `From` but we use the original
|
|
|
|
// step 2 -> make a cross link
|
|
|
|
// instead of the precompile address for consistency
|
|
|
|
// note that the transaction hash is added by state_processor.go to this receipt
|
|
|
|
evm.CXReceipt = &types.CXReceipt{ |
|
|
|
// and that the receiving shard does not care about the `From` but we use the original
|
|
|
|
From: fromAddress, |
|
|
|
// instead of the precompile address for consistency
|
|
|
|
To: &toAddress, |
|
|
|
evm.CXReceipt = &types.CXReceipt{ |
|
|
|
ShardID: fromShardID, |
|
|
|
From: fromAddress, |
|
|
|
ToShardID: toShardID, |
|
|
|
To: &toAddress, |
|
|
|
Amount: value, |
|
|
|
ShardID: fromShardID, |
|
|
|
|
|
|
|
ToShardID: toShardID, |
|
|
|
|
|
|
|
Amount: value, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return nil, errors.New("cannot call cross shard precompile again in same tx") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return nil, nil |
|
|
|
return nil, nil |
|
|
|
} |
|
|
|
} |
|
|
|