-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Token Claim and Cancel Transaction (#2499)
* feat: add airdrop claim and cancel transactions Signed-off-by: Ivaylo Nikolov <[email protected]> * chore: update protobufs Signed-off-by: Ivaylo Nikolov <[email protected]> * feat: update commit messages Signed-off-by: Ivaylo Nikolov <[email protected]> * test: add unit tests for cancel and claim Signed-off-by: Ivaylo Nikolov <[email protected]> * wip(test): add integration tests for cancel and claim transactions Signed-off-by: Ivaylo Nikolov <[email protected]> * fix: claim used the wrong channel function Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: rename transaction name Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: remove claim references in airdropcancel integration test Signed-off-by: Ivaylo Nikolov <[email protected]> * test(fix): fix not working test for airdrop cancel and claim Signed-off-by: Ivaylo Nikolov <[email protected]> * fix: airdropcancel transaction should work on sender not receiver Signed-off-by: Ivaylo Nikolov <[email protected]> * feat: add token airdrop example Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: rename transactions to have the same name as java Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: remove redundant imports and empty lines Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: rename transaction tests to have the same name as java sdk Signed-off-by: Ivaylo Nikolov <[email protected]> * docs: add licenses Signed-off-by: Ivaylo Nikolov <[email protected]> * fix: remove dead code from token cancel Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: consistency in constructor Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: change airdrop_supply_per_person naming Signed-off-by: Ivaylo Nikolov <[email protected]> * test: fix setting sender id Signed-off-by: Ivaylo Nikolov <[email protected]> * refactor: specify what kind of tokens are airdropped Signed-off-by: Ivaylo Nikolov <[email protected]> --------- Signed-off-by: Ivaylo Nikolov <[email protected]>
- Loading branch information
1 parent
dda20d3
commit 7a36f44
Showing
15 changed files
with
2,214 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*- | ||
* | ||
* Hedera JavaScript SDK | ||
* | ||
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import Transaction from "../transaction/Transaction.js"; | ||
|
||
/** | ||
* @typedef {import("../token/PendingAirdropId.js").default} PendingAirdropId | ||
*/ | ||
export default class AirdropPendingTransaction extends Transaction { | ||
/** | ||
* @param {object} [props] | ||
* @param {PendingAirdropId[]} [props.pendingAirdropIds] | ||
*/ | ||
constructor(props) { | ||
/** | ||
* @private | ||
* @type {PendingAirdropId[]} | ||
*/ | ||
super(); | ||
|
||
/** | ||
* @private | ||
* @type {PendingAirdropId[]} | ||
*/ | ||
this._pendingAirdropIds = []; | ||
|
||
if (props?.pendingAirdropIds != null) { | ||
this._pendingAirdropIds = props.pendingAirdropIds; | ||
} | ||
} | ||
|
||
/** | ||
* @returns {PendingAirdropId[]} | ||
*/ | ||
get pendingAirdropIds() { | ||
return this._pendingAirdropIds; | ||
} | ||
|
||
/** | ||
* | ||
* @param {PendingAirdropId} pendingAirdropId | ||
* @returns {this} | ||
*/ | ||
addPendingAirdropId(pendingAirdropId) { | ||
this._requireNotFrozen(); | ||
this._pendingAirdropIds.push(pendingAirdropId); | ||
return this; | ||
} | ||
|
||
/** | ||
* | ||
* @param {PendingAirdropId[]} pendingAirdropIds | ||
* @returns {this} | ||
*/ | ||
setPendingAirdropIds(pendingAirdropIds) { | ||
this._requireNotFrozen(); | ||
this._pendingAirdropIds = pendingAirdropIds; | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,23 @@ | ||
/*- | ||
* | ||
* Hedera JavaScript SDK | ||
* | ||
* Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
/** | ||
* @namespace proto | ||
* @typedef {import("@hashgraph/proto").proto.PendingAirdropId} HashgraphProto.proto.PendingAirdropId | ||
|
@@ -11,18 +31,27 @@ export default class PendingAirdropId { | |
/** | ||
* | ||
* @param {object} props | ||
* @param {AccountId} props.senderId | ||
* @param {AccountId} props.receiverId | ||
* @param {AccountId} [props.senderId] | ||
* @param {AccountId} [props.receiverId] | ||
* @param {TokenId?} props.tokenId | ||
* @param {NftId?} props.nftId | ||
*/ | ||
constructor(props) { | ||
this.senderId = props.senderId; | ||
this.receiverId = props.receiverId; | ||
this._senderId = null; | ||
this._receiverId = null; | ||
this._tokenId = null; | ||
this._nftId = null; | ||
|
||
if (props.receiverId) { | ||
this._receiverId = props.receiverId; | ||
} | ||
if (props.senderId) { | ||
this._senderId = props.senderId; | ||
} | ||
if (props.tokenId) { | ||
this.tokenId = new TokenId(props.tokenId); | ||
this._tokenId = new TokenId(props.tokenId); | ||
} else if (props.nftId) { | ||
this.nftId = new NftId(props.nftId?.tokenId, props.nftId?.serial); | ||
this._nftId = new NftId(props.nftId?.tokenId, props.nftId?.serial); | ||
} | ||
} | ||
|
||
|
@@ -59,15 +88,80 @@ export default class PendingAirdropId { | |
}); | ||
} | ||
|
||
/** | ||
* | ||
* @param {AccountId} senderId | ||
* @returns | ||
Check warning on line 94 in src/token/PendingAirdropId.js GitHub Actions / Test using Node 16
Check warning on line 94 in src/token/PendingAirdropId.js GitHub Actions / Integration Tests on Node 16
Check warning on line 94 in src/token/PendingAirdropId.js GitHub Actions / Integration Tests on Node 18
Check warning on line 94 in src/token/PendingAirdropId.js GitHub Actions / Build using Node 16
Check warning on line 94 in src/token/PendingAirdropId.js GitHub Actions / Build using Node 18
|
||
*/ | ||
setSenderid(senderId) { | ||
this._senderId = senderId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param {AccountId} receiverId | ||
* @returns {this} | ||
*/ | ||
setReceiverId(receiverId) { | ||
this._receiverId = receiverId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param {TokenId} tokenId | ||
* @returns {this} | ||
*/ | ||
setTokenId(tokenId) { | ||
this._tokenId = tokenId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @param {NftId} nftId | ||
* @returns {this} | ||
*/ | ||
setNftId(nftId) { | ||
this._nftId = nftId; | ||
return this; | ||
} | ||
|
||
/** | ||
* @returns {?AccountId} | ||
*/ | ||
get senderId() { | ||
return this._senderId; | ||
} | ||
|
||
/** | ||
* @returns {?AccountId} | ||
*/ | ||
get receiverId() { | ||
return this._receiverId; | ||
} | ||
|
||
/** | ||
* @returns {?TokenId} | ||
*/ | ||
get tokenId() { | ||
return this._tokenId; | ||
} | ||
|
||
/** | ||
* @returns {?NftId} | ||
*/ | ||
get nftId() { | ||
return this._nftId; | ||
} | ||
|
||
/** | ||
* @returns {HashgraphProto.proto.PendingAirdropId} | ||
*/ | ||
toBytes() { | ||
return { | ||
senderId: this.senderId._toProtobuf(), | ||
receiverId: this.receiverId._toProtobuf(), | ||
fungibleTokenType: this.tokenId?._toProtobuf(), | ||
nonFungibleToken: this.nftId?._toProtobuf(), | ||
senderId: this.senderId?._toProtobuf(), | ||
receiverId: this._receiverId?._toProtobuf(), | ||
fungibleTokenType: this._tokenId?._toProtobuf(), | ||
nonFungibleToken: this._nftId?._toProtobuf(), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.