Skip to content

Commit

Permalink
resolved conflicts with develop
Browse files Browse the repository at this point in the history
Signed-off-by: Georgi Georgiev <[email protected]>
  • Loading branch information
georg-getz committed Oct 27, 2022
1 parent 1af0868 commit 99a0c2a
Show file tree
Hide file tree
Showing 20 changed files with 1,074 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ private ParsingConstants() {

// struct types
public static final String EXPIRY = "(uint32,address,uint32)";
public static final String EXPIRY_V2 = "(int32,address,int32)";
public static final String FIXED_FEE = "(uint32,address,bool,bool,address)";
public static final String FIXED_FEE_V2 = "(int64,address,bool,bool,address)";
public static final String FRACTIONAL_FEE = "(uint32,uint32,uint32,uint32,bool,address)";
public static final String FRACTIONAL_FEE_V2 = "(int64,int64,int64,int64,bool,address)";
public static final String KEY_VALUE = "(bool,address,bytes,bytes,address)";
public static final String ROYALTY_FEE = "(uint32,uint32,uint32,address,bool,address)";
public static final String ROYALTY_FEE_V2 = "(int64,int64,int64,address,bool,address)";
public static final String TOKEN_KEY = "(uint256," + KEY_VALUE + ")";

public static final String HEDERA_TOKEN =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ private AbiConstants() {
public static final int ABI_ID_TRANSFER_NFT = 0x5cfc9011;
// mintToken(address token, uint64 amount, bytes[] memory metadata)
public static final int ABI_ID_MINT_TOKEN = 0x278e0b88;
// mintToken(address token, int64 amount, bytes[] memory metadata)
public static final int ABI_ID_MINT_TOKEN_V2 = 0xe0f4059a;
// burnToken(address token, uint64 amount, int64[] memory serialNumbers)
public static final int ABI_ID_BURN_TOKEN = 0xacb9cff9;
// burnToken(address token, int64 amount, int64[] memory serialNumbers)
public static final int ABI_ID_BURN_TOKEN_V2 = 0xd6910d06;
// deleteToken(address token)
public static final int ABI_ID_DELETE_TOKEN = 0xf069f712;
// associateTokens(address account, address[] memory tokens)
Expand Down Expand Up @@ -108,6 +112,8 @@ private AbiConstants() {
public static final int ABI_ID_ERC_TOKEN_URI_NFT = 0xc87b56dd;
// wipeTokenAccount(address, address, uint32)
public static final int ABI_WIPE_TOKEN_ACCOUNT_FUNGIBLE = 0x9790686d;
// wipeTokenAccount(address, address, int32)
public static final int ABI_WIPE_TOKEN_ACCOUNT_FUNGIBLE_V2 = 0x2d279ec6;
// wipeTokenAccountNFT(address, address, int64[])
public static final int ABI_WIPE_TOKEN_ACCOUNT_NFT = 0xf7f38e26;
// isFrozen(address token, address account)
Expand All @@ -118,8 +124,10 @@ private AbiConstants() {
public static final int ABI_ID_UNFREEZE = 0x52f91387;
// updateTokenInfo(address token, HederaToken tokenInfo)
public static final int ABI_ID_UPDATE_TOKEN_INFO = 0x2cccc36f;
// updateTokenKeys(address token, TokenKey [])
// updateTokenInfo(address token, HederaToken tokenInfo)
public static final int ABI_ID_UPDATE_TOKEN_INFO_V2 = 0x18370d34;
// updateTokenInfo(address token, HederaToken tokenInfo)
public static final int ABI_ID_UPDATE_TOKEN_INFO_V3 = 0x1d6d6529;
// updateTokenKeys(address token, TokenKey [])
public static final int ABI_ID_UPDATE_TOKEN_KEYS = 0x6fc3cbaf;
// getTokenKey(address token, uint tokenType)
Expand All @@ -141,6 +149,8 @@ private AbiConstants() {
public static final int ABI_ID_CREATE_FUNGIBLE_TOKEN = 0x7812a04b;
// createFungibleToken(HederaToken memory token, uint64 initialTotalSupply, uint32 decimals)
public static final int ABI_ID_CREATE_FUNGIBLE_TOKEN_V2 = 0xc23baeb6;
// createFungibleToken(HederaToken memory token, int64 initialTotalSupply, int32 decimals)
public static final int ABI_ID_CREATE_FUNGIBLE_TOKEN_V3 = 0x2c1e9423;
// createFungibleTokenWithCustomFees(
// HederaToken memory token,
// uint initialTotalSupply,
Expand All @@ -155,11 +165,20 @@ private AbiConstants() {
// FixedFee[] memory fixedFees,
// FractionalFee[] memory fractionalFees)
public static final int ABI_ID_CREATE_FUNGIBLE_TOKEN_WITH_FEES_V2 = 0xb937581a;
// createFungibleTokenWithCustomFees(
// HederaToken memory token,
// int64 initialTotalSupply,
// int32 decimals,
// FixedFee[] memory fixedFees,
// FractionalFee[] memory fractionalFees)
public static final int ABI_ID_CREATE_FUNGIBLE_TOKEN_WITH_FEES_V3 = 0x6daa94d8;
// createNonFungibleToken(HederaToken memory token)
public static final int ABI_ID_CREATE_NON_FUNGIBLE_TOKEN = 0x9dc711e0;
// createNonFungibleToken(HederaToken memory token)
// HederaToken field maxSupply updated to int64
public static final int ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_V2 = 0x9c89bb35;
// createNonFungibleToken(HederaToken memory token)
public static final int ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_V3 = 0xa4bcba95;
// createNonFungibleTokenWithCustomFees(
// HederaToken memory token,
// FixedFee[] memory fixedFees,
Expand All @@ -171,6 +190,11 @@ private AbiConstants() {
// RoyaltyFee[] memory royaltyFees)
// HederaToken field maxSupply updated to int64
public static final int ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_WITH_FEES_V2 = 0x45733969;
// createNonFungibleTokenWithCustomFees(
// HederaToken memory token,
// FixedFee[] memory fixedFees,
// RoyaltyFee[] memory royaltyFees)
public static final int ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_WITH_FEES_V3 = 0xaddb7110;

// **** HIP-514 function selectors ****
// getFungibleTokenInfo(address token)
Expand Down Expand Up @@ -199,4 +223,6 @@ private AbiConstants() {
public static final int ABI_ID_GET_TOKEN_EXPIRY_INFO = 0xd614cdb8;
// updateTokenExpiryInfo(address token, Expiry expiryInfoStruct)
public static final int ABI_ID_UPDATE_TOKEN_EXPIRY_INFO = 0x593d6e82;
// updateTokenExpiryInfo(address token, Expiry expiryInfoStruct)
public static final int ABI_ID_UPDATE_TOKEN_EXPIRY_INFO_V2 = 0x4a089f09;
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,8 @@ void prepareComputation(final Bytes input, final UnaryOperator<byte[]> aliasReso
functionId,
senderAddress,
impliedTransfersMarshal));
case AbiConstants.ABI_ID_MINT_TOKEN -> new MintPrecompile(
case AbiConstants.ABI_ID_MINT_TOKEN,
AbiConstants.ABI_ID_MINT_TOKEN_V2-> new MintPrecompile(
ledgers,
encoder,
updater.aliases(),
Expand All @@ -302,16 +303,19 @@ void prepareComputation(final Bytes input, final UnaryOperator<byte[]> aliasReso
sideEffectsTracker,
syntheticTxnFactory,
infrastructureFactory,
precompilePricingUtils);
case AbiConstants.ABI_ID_BURN_TOKEN -> new BurnPrecompile(
precompilePricingUtils,
functionId);
case AbiConstants.ABI_ID_BURN_TOKEN,
AbiConstants.ABI_ID_BURN_TOKEN_V2 -> new BurnPrecompile(
ledgers,
encoder,
updater.aliases(),
sigsVerifier,
sideEffectsTracker,
syntheticTxnFactory,
infrastructureFactory,
precompilePricingUtils);
precompilePricingUtils,
functionId);
case AbiConstants.ABI_ID_ASSOCIATE_TOKENS -> new MultiAssociatePrecompile(
ledgers,
updater.aliases(),
Expand Down Expand Up @@ -453,14 +457,16 @@ void prepareComputation(final Bytes input, final UnaryOperator<byte[]> aliasReso
syntheticTxnFactory,
infrastructureFactory,
precompilePricingUtils);
case AbiConstants.ABI_WIPE_TOKEN_ACCOUNT_FUNGIBLE -> new WipeFungiblePrecompile(
case AbiConstants.ABI_WIPE_TOKEN_ACCOUNT_FUNGIBLE,
AbiConstants.ABI_WIPE_TOKEN_ACCOUNT_FUNGIBLE_V2-> new WipeFungiblePrecompile(
ledgers,
updater.aliases(),
sigsVerifier,
sideEffectsTracker,
syntheticTxnFactory,
infrastructureFactory,
precompilePricingUtils);
precompilePricingUtils,
functionId);
case AbiConstants.ABI_WIPE_TOKEN_ACCOUNT_NFT -> new WipeNonFungiblePrecompile(
ledgers,
updater.aliases(),
Expand Down Expand Up @@ -498,7 +504,8 @@ void prepareComputation(final Bytes input, final UnaryOperator<byte[]> aliasReso
infrastructureFactory,
precompilePricingUtils);
case AbiConstants.ABI_ID_UPDATE_TOKEN_INFO,
AbiConstants.ABI_ID_UPDATE_TOKEN_INFO_V2 -> new TokenUpdatePrecompile(
AbiConstants.ABI_ID_UPDATE_TOKEN_INFO_V2,
AbiConstants.ABI_ID_UPDATE_TOKEN_INFO_V3-> new TokenUpdatePrecompile(
ledgers,
updater.aliases(),
sigsVerifier,
Expand Down Expand Up @@ -675,8 +682,11 @@ yield switch (nestedFunctionSelector) {
AbiConstants.ABI_ID_CREATE_FUNGIBLE_TOKEN_V2,
AbiConstants.ABI_ID_CREATE_FUNGIBLE_TOKEN_WITH_FEES_V2,
AbiConstants.ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_V2,
AbiConstants
.ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_WITH_FEES_V2 -> (dynamicProperties
AbiConstants.ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_WITH_FEES_V2,
AbiConstants.ABI_ID_CREATE_FUNGIBLE_TOKEN_V3,
AbiConstants.ABI_ID_CREATE_FUNGIBLE_TOKEN_WITH_FEES_V3,
AbiConstants.ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_V3,
AbiConstants.ABI_ID_CREATE_NON_FUNGIBLE_TOKEN_WITH_FEES_V3 -> (dynamicProperties
.isHTSPrecompileCreateEnabled())
? new TokenCreatePrecompile(
ledgers,
Expand Down Expand Up @@ -747,14 +757,17 @@ yield switch (nestedFunctionSelector) {
precompilePricingUtils,
currentView);
case AbiConstants
.ABI_ID_UPDATE_TOKEN_EXPIRY_INFO -> new UpdateTokenExpiryInfoPrecompile(
.ABI_ID_UPDATE_TOKEN_EXPIRY_INFO,
AbiConstants
.ABI_ID_UPDATE_TOKEN_EXPIRY_INFO_V2-> new UpdateTokenExpiryInfoPrecompile(
ledgers,
updater.aliases(),
sigsVerifier,
sideEffectsTracker,
syntheticTxnFactory,
infrastructureFactory,
precompilePricingUtils);
precompilePricingUtils,
functionId);
case AbiConstants.ABI_ID_TRANSFER_FROM -> checkFeatureFlag(
dynamicProperties.areAllowancesEnabled(),
() ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static com.hedera.services.contracts.ParsingConstants.ARRAY_BRACKETS;
import static com.hedera.services.contracts.ParsingConstants.EXPIRY;
import static com.hedera.services.contracts.ParsingConstants.EXPIRY_V2;
import static com.hedera.services.contracts.ParsingConstants.TOKEN_KEY;
import static com.hedera.services.utils.EntityIdUtils.accountIdFromEvmAddress;

Expand Down Expand Up @@ -52,7 +53,7 @@ public class DecodingFacade {
private static final String KEY_VALUE_DECODER = "(bool,bytes32,bytes,bytes,bytes32)";
public static final String TOKEN_KEY_DECODER = "(int32," + KEY_VALUE_DECODER + ")";
public static final String EXPIRY_DECODER = "(int64,bytes32,int64)";

public static final String EXPIRY_DECODER_V2 = "(int32,bytes32,int32)";
public static final String FIXED_FEE_DECODER = "(int64,bytes32,bool,bool,bytes32)";
public static final String FRACTIONAL_FEE_DECODER = "(int64,int64,int64,int64,bool,bytes32)";
public static final String ROYALTY_FEE_DECODER = "(int64,int64,int64,bytes32,bool,bytes32)";
Expand All @@ -71,13 +72,27 @@ public class DecodingFacade {
+ ","
+ EXPIRY
+ ")";
public static final String HEDERA_TOKEN_STRUCT_V3 =
"(string,string,address,string,bool,int64,bool,"
+ TOKEN_KEY
+ ARRAY_BRACKETS
+ ","
+ EXPIRY_V2
+ ")";
public static final String HEDERA_TOKEN_STRUCT_DECODER =
"(string,string,bytes32,string,bool,int64,bool,"
+ TOKEN_KEY_DECODER
+ ARRAY_BRACKETS
+ ","
+ EXPIRY_DECODER
+ ")";
public static final String HEDERA_TOKEN_STRUCT_DECODER_V2 =
"(string,string,bytes32,string,bool,int64,bool,"
+ TOKEN_KEY_DECODER
+ ARRAY_BRACKETS
+ ","
+ EXPIRY_DECODER_V2
+ ")";

private DecodingFacade() {
throw new UnsupportedOperationException("Utility Class");
Expand Down Expand Up @@ -127,6 +142,18 @@ public static TokenExpiryWrapper decodeTokenExpiry(
autoRenewPeriod);
}

public static TokenExpiryWrapper decodeTokenExpiryV2(
@NotNull final Tuple expiryTuple, final UnaryOperator<byte[]> aliasResolver) {
final var second = (int) expiryTuple.get(0);
final var autoRenewAccount =
convertLeftPaddedAddressToAccountId(expiryTuple.get(1), aliasResolver);
final var autoRenewPeriod = (int) expiryTuple.get(2);
return new TokenExpiryWrapper(
second,
autoRenewAccount.getAccountNum() == 0 ? null : autoRenewAccount,
autoRenewPeriod);
}

public static Tuple decodeFunctionCall(
@NotNull final Bytes input, final Bytes selector, final ABIType<Tuple> decoder) {
if (!selector.equals(input.slice(0, FUNCTION_SELECTOR_BYTES_LENGTH))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.hedera.services.ledger.accounts.ContractAliases;
import com.hedera.services.state.submerkle.ExpirableTxnRecord;
import com.hedera.services.store.contracts.WorldLedgers;
import com.hedera.services.store.contracts.precompile.AbiConstants;
import com.hedera.services.store.contracts.precompile.InfrastructureFactory;
import com.hedera.services.store.contracts.precompile.SyntheticTxnFactory;
import com.hedera.services.store.contracts.precompile.codec.BurnWrapper;
Expand All @@ -43,6 +44,7 @@
import com.hederahashgraph.api.proto.java.ResponseCodeEnum;
import com.hederahashgraph.api.proto.java.Timestamp;
import com.hederahashgraph.api.proto.java.TransactionBody;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
Expand All @@ -52,11 +54,15 @@
import org.hyperledger.besu.evm.frame.MessageFrame;

public class BurnPrecompile extends AbstractWritePrecompile {
private final int functionId;
private static final List<Long> NO_SERIAL_NOS = Collections.emptyList();
private static final String BURN = String.format(FAILURE_MESSAGE, "burn");
private static final Function BURN_TOKEN_FUNCTION =
new Function("burnToken(address,uint64,int64[])", INT);
private static final Function BURN_TOKEN_FUNCTION_V2 =
new Function("burnToken(address,int64,int64[])", INT);
private static final Bytes BURN_TOKEN_SELECTOR = Bytes.wrap(BURN_TOKEN_FUNCTION.selector());
private static final Bytes BURN_TOKEN_SELECTOR_V2 = Bytes.wrap(BURN_TOKEN_FUNCTION_V2.selector());
private static final ABIType<Tuple> BURN_TOKEN_DECODER =
TypeFactory.create("(bytes32,int64,int64[])");
private final EncodingFacade encoder;
Expand All @@ -72,17 +78,24 @@ public BurnPrecompile(
final SideEffectsTracker sideEffects,
final SyntheticTxnFactory syntheticTxnFactory,
final InfrastructureFactory infrastructureFactory,
final PrecompilePricingUtils pricingUtils) {
final PrecompilePricingUtils pricingUtils,
final int functionId) {
super(ledgers, sideEffects, syntheticTxnFactory, infrastructureFactory, pricingUtils);
this.encoder = encoder;
this.aliases = aliases;
this.sigsVerifier = sigsVerifier;
this.functionId = functionId;
}

@Override
public TransactionBody.Builder body(
final Bytes input, final UnaryOperator<byte[]> aliasResolver) {
burnOp = decodeBurn(input);
burnOp =
switch (functionId) {
case AbiConstants.ABI_ID_BURN_TOKEN -> decodeBurn(input);
case AbiConstants.ABI_ID_BURN_TOKEN_V2 -> decodeBurnV2(input);
default -> null;
};
transactionBody = syntheticTxnFactory.createBurn(burnOp);
return transactionBody;
}
Expand Down Expand Up @@ -159,4 +172,20 @@ public static BurnWrapper decodeBurn(final Bytes input) {
tokenID, Arrays.stream(serialNumbers).boxed().toList());
}
}

public static BurnWrapper decodeBurnV2(final Bytes input) {
final Tuple decodedArguments =
decodeFunctionCall(input, BURN_TOKEN_SELECTOR_V2, BURN_TOKEN_DECODER);

final var tokenID = convertAddressBytesToTokenID(decodedArguments.get(0));
final var fungibleAmount = (long) decodedArguments.get(1);
final var serialNumbers = (long[]) decodedArguments.get(2);

if (fungibleAmount > 0) {
return BurnWrapper.forFungible(tokenID, fungibleAmount);
} else {
return BurnWrapper.forNonFungible(
tokenID, Arrays.stream(serialNumbers).boxed().toList());
}
}
}
Loading

0 comments on commit 99a0c2a

Please sign in to comment.