-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2073 support type ticket deprecated in michelson encoder #2094
Merged
hui-an-yang
merged 23 commits into
lima
from
2073-support-type-ticket_deprecated-in-michelson-encoder
Nov 4, 2022
Merged
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
47cf160
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang 53bf5c5
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang eddeb1d
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang ac9bd70
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang ca9577d
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang 8c1643d
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang d34128b
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang ad53532
Merge branch 'master' of github.com:ecadlabs/taquito
hui-an-yang 3280638
feat: exposed setParserProvider configuration through TezosToolkit
hui-an-yang a82f23a
test: added integration tests using setParserProvider with TezosToolkit
hui-an-yang 7f7c813
docs: updated starting production server commands with taquito-test-d…
hui-an-yang 77d79f4
test: removed unnecessory console.log
hui-an-yang c03f145
Merge branch 'master' of github.com:ecadlabs/taquito into 660-support…
hui-an-yang 1a12a83
chore: update vite to latest version
hui-an-yang ef0ca04
docs: fixed some typos in doc to address comments
hui-an-yang 5579da2
Merge branch 'master' of github.com:ecadlabs/taquito into 660-support…
hui-an-yang 04c0a87
1630 ballot operation support in contract API (#2050)
dsawali 6be3114
660 support customize parser options (#2061)
hui-an-yang 1359969
feat(n): support type ticket_deprecated in michelson encoder
hui-an-yang 59fccf4
contract-security-non-existent-KT-address: use rpc (#2091)
arvidj 910b295
Merge pull request #2092 from arvidj/arvid@2091-use-rpc-in-contract-s…
roxaneletourneau 0d6dd3e
Merge branch 'master' of github.com:ecadlabs/taquito into 2073-suppor…
hui-an-yang 4158036
fix: address comment with TicketDeprecatedEncodeError and fix unit tests
hui-an-yang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
106 changes: 106 additions & 0 deletions
106
packages/taquito-michelson-encoder/src/tokens/ticket-deprecated.ts
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,106 @@ | ||
import { TicketDeprecatedTokenSchema } from '../schema/types'; | ||
import { IntToken } from './comparable/int'; | ||
import { ContractToken } from './contract'; | ||
import { Token, TokenFactory, Semantic, SemanticEncoding } from './token'; | ||
|
||
/** | ||
* @category Error | ||
* @description Error that indicates a failure when encoding and sending a ticket to the blockchain | ||
*/ | ||
export class EncodeTicketError extends Error { | ||
name = 'TicketEncodeError'; | ||
|
||
constructor() { | ||
super('Tickets cannot be sent to the blockchain; they are created on-chain'); | ||
} | ||
} | ||
|
||
const ticketerType = { prim: 'contract' }; | ||
const amountType = { prim: 'int' }; | ||
|
||
export class TicketDeprecatedToken extends Token { | ||
static prim: 'ticket_deprecated' = 'ticket_deprecated' as const; | ||
|
||
constructor( | ||
protected val: { prim: string; args: any[]; annots: any[] }, | ||
protected idx: number, | ||
protected fac: TokenFactory | ||
) { | ||
super(val, idx, fac); | ||
} | ||
|
||
get valueToken() { | ||
return this.createToken(this.val.args[0], this.idx); | ||
} | ||
|
||
public Encode(_args: any[]): any { | ||
throw new EncodeTicketError(); | ||
} | ||
|
||
public EncodeObject(args: any, semantic?: SemanticEncoding): any { | ||
if (semantic && semantic[TicketDeprecatedToken.prim]) { | ||
return semantic[TicketDeprecatedToken.prim](args, this.val); | ||
} | ||
throw new EncodeTicketError(); | ||
} | ||
|
||
public Execute(val: any, semantics?: Semantic) { | ||
if (semantics && semantics[TicketDeprecatedToken.prim]) { | ||
return semantics[TicketDeprecatedToken.prim](val, this.val); | ||
} | ||
const ticketer = this.createToken(ticketerType, this.idx); | ||
const value = this.valueToken; | ||
const amount = this.createToken(amountType, this.idx); | ||
|
||
if (undefined === val.args[2] && undefined !== val.args[1].args) { | ||
return { | ||
ticketer: ticketer.Execute(val.args[0], semantics), | ||
value: value.Execute(val.args[1].args[0], semantics), | ||
amount: amount.Execute(val.args[1].args[1], semantics), | ||
}; | ||
} | ||
|
||
return { | ||
ticketer: ticketer.Execute(val.args[0], semantics), | ||
value: value.Execute(val.args[1], semantics), | ||
amount: amount.Execute(val.args[2], semantics), | ||
}; | ||
} | ||
|
||
/** | ||
* @deprecated ExtractSchema has been deprecated in favor of generateSchema | ||
* | ||
*/ | ||
public ExtractSchema() { | ||
return { | ||
ticketer: ContractToken.prim, | ||
value: this.valueToken.ExtractSchema(), | ||
amount: IntToken.prim, | ||
}; | ||
} | ||
|
||
generateSchema(): TicketDeprecatedTokenSchema { | ||
return { | ||
__michelsonType: TicketDeprecatedToken.prim, | ||
schema: { | ||
value: this.valueToken.generateSchema(), | ||
ticketer: { | ||
__michelsonType: ContractToken.prim, | ||
schema: ContractToken.prim, | ||
}, | ||
amount: { | ||
__michelsonType: IntToken.prim, | ||
schema: IntToken.prim, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
findAndReturnTokens(tokenToFind: string, tokens: Token[]) { | ||
if (TicketDeprecatedToken.prim === tokenToFind) { | ||
tokens.push(this); | ||
} | ||
this.valueToken.findAndReturnTokens(tokenToFind, tokens); | ||
return tokens; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did we need a TicketDeprecatedEncodeError instead? In essence, it seems to do the same job as TicketEncodeError just more descriptive to be ticket-deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I think TicketDeprecatedEncodeError would be more descriptive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, comment addressed in the new commit :)