use of com.hederahashgraph.api.proto.java.TokenType in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method tokenSupplyTransaction.
private Transaction tokenSupplyTransaction(TokenType tokenType, boolean mint) {
var serialNumbers = List.of(1L, 2L, 3L);
Transaction transaction = null;
if (mint) {
transaction = buildTransaction(builder -> {
builder.getTokenMintBuilder().setToken(TOKEN_ID);
if (tokenType == FUNGIBLE_COMMON) {
builder.getTokenMintBuilder().setAmount(10);
} else {
builder.getTokenMintBuilder().addAllMetadata(Collections.nCopies(serialNumbers.size(), ByteString.copyFromUtf8(METADATA)));
}
});
} else {
transaction = buildTransaction(builder -> {
builder.getTokenBurnBuilder().setToken(TOKEN_ID);
if (tokenType == FUNGIBLE_COMMON) {
builder.getTokenBurnBuilder().setAmount(10);
} else {
builder.getTokenBurnBuilder().addAllSerialNumbers(serialNumbers);
}
});
}
return transaction;
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class OpUsageCtxHelperTest method getMetaForTokenMintWorks.
@Test
void getMetaForTokenMintWorks() {
TokenMintTransactionBody mintTxnBody = getUniqueTokenMintOp();
TransactionBody txn = getTxnBody(mintTxnBody);
given(accessor.getTxn()).willReturn(txn);
given(accessor.getSubType()).willReturn(TOKEN_NON_FUNGIBLE_UNIQUE);
Optional<TokenType> tokenType = Optional.of(TokenType.NON_FUNGIBLE_UNIQUE);
given(workingView.tokenWith(target)).willReturn(Optional.of(extant));
final var tokenMintMeta = subject.metaForTokenMint(accessor);
// then:
assertEquals(34, tokenMintMeta.getBpt());
assertEquals(TOKEN_NON_FUNGIBLE_UNIQUE, tokenMintMeta.getSubType());
assertEquals(12345670, tokenMintMeta.getRbs());
assertEquals(80, tokenMintMeta.getTransferRecordDb());
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class ContractCallSuite method workingHoursDemo.
private HapiApiSpec workingHoursDemo() {
final var initcode = "initcode";
final var gasToOffer = 4_000_000;
final var workingHours = "workingHours";
final var ticketToken = "ticketToken";
final var adminKey = "admin";
final var treasury = "treasury";
final var user = "user";
final var newSupplyKey = "newSupplyKey";
final var ticketTaking = "ticketTaking";
final var ticketWorking = "ticketWorking";
final var mint = "minting";
final var burn = "burning";
final var preMints = List.of(ByteString.copyFromUtf8("HELLO"), ByteString.copyFromUtf8("GOODBYE"));
final AtomicLong ticketSerialNo = new AtomicLong();
return defaultHapiSpec("WorkingHoursDemo").given(newKeyNamed(adminKey), cryptoCreate(treasury), // we need a new user, expiry to 1 Jan 2100 costs 11M gas for token associate
cryptoCreate(user), cryptoTransfer(TokenMovement.movingHbar(ONE_HUNDRED_HBARS).between(GENESIS, user)), tokenCreate(ticketToken).treasury(treasury).tokenType(TokenType.NON_FUNGIBLE_UNIQUE).initialSupply(0L).supplyType(TokenSupplyType.INFINITE).adminKey(adminKey).supplyKey(adminKey), mintToken(ticketToken, preMints).via(mint), burnToken(ticketToken, List.of(1L)).via(burn), fileCreate(initcode), updateLargeFile(GENESIS, initcode, extractByteCode(WORKING_HOURS_USER_BYTECODE_PATH))).when(withOpContext((spec, opLog) -> {
final var registry = spec.registry();
final var tokenId = registry.getTokenID(ticketToken);
final var treasuryId = registry.getAccountID(treasury);
final var creation = contractCreate(workingHours, WORKING_HOURS_CONS, tokenId.getTokenNum(), treasuryId.getAccountNum()).bytecode(initcode).gas(gasToOffer);
allRunFor(spec, creation);
}), newKeyNamed(newSupplyKey).shape(KeyShape.CONTRACT.signedWith(workingHours)), tokenUpdate(ticketToken).supplyKey(newSupplyKey)).then(/* Take a ticket */
contractCall(workingHours, WORKING_HOURS_TAKE_TICKET).payingWith(user).gas(4_000_000).via(ticketTaking).alsoSigningWithFullPrefix(treasury).exposingResultTo(result -> {
log.info("Explicit mint result is {}", result);
ticketSerialNo.set(((BigInteger) result[0]).longValueExact());
}), getTxnRecord(ticketTaking), getAccountBalance(user).hasTokenBalance(ticketToken, 1L), /* Our ticket number is 3 (b/c of the two pre-mints), so we must call
* work twice before the contract will actually accept our ticket. */
sourcing(() -> contractCall(workingHours, WORKING_HOURS_WORK_TICKET, ticketSerialNo.get()).gas(2_000_000).payingWith(user)), getAccountBalance(user).hasTokenBalance(ticketToken, 1L), sourcing(() -> contractCall(workingHours, WORKING_HOURS_WORK_TICKET, ticketSerialNo.get()).gas(2_000_000).payingWith(user).via(ticketWorking)), getAccountBalance(user).hasTokenBalance(ticketToken, 0L), getTokenInfo(ticketToken).hasTotalSupply(1L), /* Review the history */
getTxnRecord(ticketTaking).andAllChildRecords().logged(), getTxnRecord(ticketWorking).andAllChildRecords().logged());
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class ContractKeysHTSSuite method callForMintWithContractKey.
private HapiApiSpec callForMintWithContractKey() {
final var theAccount = "anybody";
final var mintContractByteCode = "mintContractByteCode";
final var amount = 10L;
final var fungibleToken = "fungibleToken";
final var theContract = "mintContract";
final var firstMintTxn = "firstMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("callForMintWithContractKey").given(newKeyNamed(MULTI_KEY), cryptoCreate(theAccount).balance(10 * ONE_HUNDRED_HBARS), cryptoCreate(TOKEN_TREASURY), fileCreate(mintContractByteCode).payingWith(theAccount), updateLargeFile(theAccount, mintContractByteCode, extractByteCode(ContractResources.ORDINARY_CALLS_CONTRACT)), tokenCreate(fungibleToken).tokenType(FUNGIBLE_COMMON).initialSupply(0).treasury(TOKEN_TREASURY).adminKey(MULTI_KEY).supplyKey(MULTI_KEY).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(theContract).bytecode(mintContractByteCode).payingWith(theAccount).gas(GAS_TO_OFFER))).then(withOpContext((spec, opLog) -> allRunFor(spec, newKeyNamed("contractKey").shape(CONTRACT_KEY_SHAPE.signedWith(sigs(ON, theContract))), tokenUpdate(fungibleToken).supplyKey("contractKey"), contractCall(theContract, MINT_TOKEN_ORDINARY_CALL, asAddress(spec.registry().getTokenID(fungibleToken)), amount, new byte[] {}).via(firstMintTxn).payingWith(theAccount))), childRecordsCheck(firstMintTxn, SUCCESS, recordWith().status(SUCCESS).tokenTransfers(changingFungibleBalances().including(fungibleToken, TOKEN_TREASURY, 10)).newTotalSupply(10)), getTokenInfo(fungibleToken).hasTotalSupply(amount), getAccountBalance(TOKEN_TREASURY).hasTokenBalance(fungibleToken, amount));
}
use of com.hederahashgraph.api.proto.java.TokenType in project hedera-services by hashgraph.
the class ContractMintHTSSuite method helloWorldFungibleMint.
private HapiApiSpec helloWorldFungibleMint() {
final var hwMintInitcode = "hwMintInitcode";
final var amount = 1_234_567L;
final var fungibleToken = "fungibleToken";
final var multiKey = "purpose";
final var contractKey = "meaning";
final var hwMint = "hwMint";
final var firstMintTxn = "firstMintTxn";
final var secondMintTxn = "secondMintTxn";
final AtomicLong fungibleNum = new AtomicLong();
return defaultHapiSpec("HelloWorldFungibleMint").given(newKeyNamed(multiKey), fileCreate(hwMintInitcode).path(ContractResources.HW_MINT_PATH), tokenCreate(fungibleToken).tokenType(TokenType.FUNGIBLE_COMMON).initialSupply(0).adminKey(multiKey).supplyKey(multiKey).exposingCreatedIdTo(idLit -> fungibleNum.set(asDotDelimitedLongArray(idLit)[2]))).when(sourcing(() -> contractCreate(hwMint, HW_MINT_CONS_ABI, fungibleNum.get()).bytecode(hwMintInitcode).gas(GAS_TO_OFFER))).then(contractCall(hwMint, HW_BRRR_CALL_ABI, amount).via(firstMintTxn).alsoSigningWithFullPrefix(multiKey), getTxnRecord(firstMintTxn).andAllChildRecords().logged(), getTokenInfo(fungibleToken).hasTotalSupply(amount), /* And now make the token contract-controlled so no explicit supply sig is required */
newKeyNamed(contractKey).shape(DELEGATE_CONTRACT.signedWith(hwMint)), tokenUpdate(fungibleToken).supplyKey(contractKey), getTokenInfo(fungibleToken).logged(), contractCall(hwMint, HW_BRRR_CALL_ABI, amount).via(secondMintTxn), getTxnRecord(secondMintTxn).andAllChildRecords().logged(), getTokenInfo(fungibleToken).hasTotalSupply(2 * amount), childRecordsCheck(secondMintTxn, SUCCESS, recordWith().status(SUCCESS).newTotalSupply(2469134L).tokenTransfers(changingFungibleBalances().including(fungibleToken, DEFAULT_PAYER, amount))));
}
Aggregations