Skip to content

Commit

Permalink
Merge pull request #42 from trustenterprises/patch/sdk-compat-fix
Browse files Browse the repository at this point in the history
Patch PHP SDK compat fix
  • Loading branch information
mattsmithies authored Aug 29, 2022
2 parents 37bcbd3 + e0df1d4 commit 9c15df7
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/handler/claimNftHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@ async function ClaimNftHandler(req, res) {
const claimablePayload = await claimableTokenCheck(claimPayload)

if (claimablePayload.error) {
return Response.unprocessibleEntity(res, claimablePayload.error)
return Response.unprocessibleEntity(res, [claimablePayload.error])
}

const { hashgraphClient } = req.context
const sendResponse = await hashgraphClient.transferNft(claimPayload)

if (sendResponse.error) {
return Response.unprocessibleEntity(res, sendResponse.error)
}

if (sendResponse) {
return Response.json(res, sendResponse)
}
Expand Down
4 changes: 4 additions & 0 deletions app/handler/mintNftHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ async function MintNftHandler(req, res) {
cid
})

if (token.errors) {
return Response.unprocessibleEntity(res, token.errors)
}

Response.json(res, token)
}

Expand Down
2 changes: 1 addition & 1 deletion app/handler/transferNftHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function TransferNftHandler(req, res) {
const sendResponse = await hashgraphClient.transferNft(transferPayload)

if (sendResponse.error) {
return Response.unprocessibleEntity(res, sendResponse)
return Response.unprocessibleEntity(res, sendResponse.error)
}

if (sendResponse) {
Expand Down
29 changes: 21 additions & 8 deletions app/hashgraph/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class HashgraphClient extends HashgraphClientContract {
const client = this.#client
const transaction = new AccountCreateTransaction()
.setKey(publicKey)
.setMaxAutomaticTokenAssociations(10)
.setInitialBalance(0.1)

const txResponse = await transaction.execute(client)
Expand Down Expand Up @@ -564,13 +565,22 @@ class HashgraphClient extends HashgraphClientContract {

// TODO: If there are issues in the future we may need to await the receipt to check.
const txResponse = await signedTx.execute(client)
const receipt = await txResponse.getReceipt(client)
const minted_serial_numbers = receipt.serials.map(serial => serial.low)

return {
token_id,
amount,
minted_serial_numbers
try {
const receipt = await txResponse.getReceipt(client)
const minted_serial_numbers = receipt.serials.map(serial => serial.low)

return {
token_id,
amount,
minted_serial_numbers
}
} catch (e) {
return {
errors: [
"Something went wrong, likely that the token id probably incorrect"
]
}
}
}

Expand All @@ -597,7 +607,9 @@ class HashgraphClient extends HashgraphClientContract {

if (!hasNft) {
return {
error: `The treasury does not hold the token ${token_id} of serial ${serial_number}`
error: [
`The treasury does not hold the token ${token_id} of serial ${serial_number}`
]
}
}

Expand All @@ -622,8 +634,9 @@ class HashgraphClient extends HashgraphClientContract {
} catch (e) {
return {
token_id,
error:
error: [
"Transfer failed, ensure that the recipient account is valid and has associated to the token"
]
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions app/utils/mirrornode.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@ const retryableMirrorQuery = async (
} catch (e) {
if (e.response.status === Status.NOT_FOUND) {
return {
error:
error: [
"Expected resource was not found, did you include a parameter like an NFT ID that isn't on ledger?"
]
}
}

if (attempts > tries) {
return {
error: `Hedera Mirrornode Overloaded after ${tries} attempts, unable to process query`
error: [
`Hedera Mirrornode Overloaded after ${tries} attempts, unable to process query`
]
}
}

Expand Down

0 comments on commit 9c15df7

Please sign in to comment.