-
Notifications
You must be signed in to change notification settings - Fork 43
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
Implementing Transaction model #56
Conversation
51749d4
to
0b0a36e
Compare
0b0a36e
to
85583cd
Compare
*/ | ||
constructor(model: TransactionModel) { | ||
if (!model) { | ||
throw new Error("Invalid model type"); |
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.
Is it sufficient that this is typed via typescript? Or is this just guarding against a nil value?
Main reason we added that to the ruby client is for better error messaging when passing in the wrong object, because there is no typing.
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.
The guard in the constructor is mainly to catch null values and give better error messages, similar to what we did in the Ruby client. While TypeScript handles type checking, having this check is still useful for making the code more robust and the errors clearer. If someone uses the SDK in plain JavaScript, this kind of check is even more important since JavaScript doesn't have built-in type checking.
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.
Lets aim to be consistent with current implementation wrt documentation (Reference: https://github.com/coinbase/coinbase-sdk-nodejs/blob/master/src/coinbase/transfer.ts)
We can choose to do these as follow ups if necessary to unblock staking team, but I would like them to be fast followed before the release if possible!
cc: @alex-stone
|
||
describe("#unsignedPayload", () => { | ||
it("returns the unsigned payload", () => { | ||
const transaction = new Transaction(model); |
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.
Lets move these out of the individual it
blocks. Its not necessary to duplicate them if the model
passed into the constructor is the same.
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.
makes sense 👍
* @class | ||
* @param model - The underlying Transaction object. | ||
*/ | ||
constructor(model: TransactionModel) { |
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.
we use private constructor in most places. Is there a reason this diverges?
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.
We have some instances where we use constructors like User, Address, and FaucetTransaction classes. How do we determine which one to use? If we plan to use another method for initialization, we will essentially have the same guard function unless there is specific logic behind it, like in the Wallet class.
src/coinbase/transaction.ts
Outdated
/** | ||
* Returns the status of the Transaction. |
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.
/** | |
* Returns the status of the Transaction. | |
/** | |
* Returns the Status of the Transaction. |
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.
JSDocs were generated using Ruby documentation, like the example below. @alex-stone you may want to update your PR too.
https://github.com/coinbase/coinbase-sdk-ruby/blob/master/lib/coinbase/transfer.rb#L134
src/coinbase/transaction.ts
Outdated
} | ||
|
||
/** | ||
* Returns the from address for the Transaction. |
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.
* Returns the from address for the Transaction. | |
* Returns the From Address ID for the Transaction. |
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.
src/coinbase/transaction.ts
Outdated
/** | ||
* Returns the from address for the Transaction. | ||
* | ||
* @returns The from address |
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.
* @returns The from address | |
* @returns The From Address ID |
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.
src/coinbase/transaction.ts
Outdated
/** | ||
* Returns whether the Transaction is in a terminal state. | ||
* | ||
* @returns Whether the Transaction is in a terminal state |
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.
* @returns Whether the Transaction is in a terminal state | |
* @returns Whether the Transaction is in a terminal State |
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.
src/coinbase/transaction.ts
Outdated
* Returns the underlying raw transaction. | ||
* | ||
* @throws {InvalidUnsignedPayload} If the payload is invalid. | ||
* @returns The raw transaction |
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.
* @returns The raw transaction | |
* @returns The ethers.js Transaction object |
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.
JSDocs will be generated with type
https://github.com/coinbase/coinbase-sdk-ruby/pull/73/files#diff-29c569c6fa5eec4929209fceeed30a30dcdfc5202ebee6f65bb1fbcfe67fe223R84
src/coinbase/transaction.ts
Outdated
/** | ||
* Returns the underlying raw transaction. | ||
* | ||
* @throws {InvalidUnsignedPayload} If the payload is invalid. |
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.
* @throws {InvalidUnsignedPayload} If the payload is invalid. | |
* @throws {InvalidUnsignedPayload} If the Unsigned Payload is invalid. |
src/coinbase/utils.ts
Outdated
@@ -102,3 +103,28 @@ export function destinationToAddressHexString(destination: Destination): string | |||
throw new Error("Unsupported type"); | |||
} | |||
} | |||
|
|||
/** | |||
* Parses an unsigned payload and returns the JSON object. |
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.
* Parses an unsigned payload and returns the JSON object. | |
* Parses an Unsigned Payload and returns the JSON object. |
src/coinbase/utils.ts
Outdated
* Parses an unsigned payload and returns the JSON object. | ||
* | ||
* @throws {InvalidUnsignedPayload} If the payload is invalid. | ||
* @param payload - The unsigned payload. |
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.
* @param payload - The unsigned payload. | |
* @param payload - The Unsigned Payload. |
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.
} as TransactionModel; | ||
}); | ||
|
||
describe("#initialize", () => { |
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.
#initialize is a ruby construct, should this be just like describe('constructor', ....
?
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 thought we wanted to follow the same structure as our Ruby tests.
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.
Lets keep the same structure but remain idiomatic to the language we are implementing in. initialize
is ruby specific in this case. Transaction
object is constructed with constructor
in Typescript.
366d5a0
to
7001562
Compare
85583cd
to
ca96717
Compare
3bbec8c
to
bbca705
Compare
import { Transaction as TransactionModel } from "../../client/api"; | ||
import { Transaction } from "./../transaction"; | ||
|
||
describe("Coinbase::Transaction", () => { |
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.
describe("Coinbase::Transaction", () => { | |
describe("Transaction", () => { |
It seems from other projects using just class name is most idiomatic.
Lets clean these up in a follow up in other files to use ClassName
to describe top level block.
#InstanceMethodName
to describe instance methods and .staticMethodName
to describe static methods.
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.
Update this we will have the most of test case refactoring/changes with [PSDK-245]
bbca705
to
1e5d379
Compare
24b84c6
to
8d3e4e9
Compare
### Added | ||
|
||
- Added Base Mainnet network support | ||
|
||
### Changed | ||
Updated the usage of `Coinbase.networkList` to `Coinbase.networks` | ||
|
||
- Updated the usage of `Coinbase.networkList` to `Coinbase.networks` | ||
### Added | ||
- Added Base Mainnet network support | ||
|
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.
Lets format the CHANGELOG.md before merge
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.
We also should add the transaction class addition to change log
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.
ah, just merged but I'm going to format in my PR
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.
no worries. Lets just change before the release.
What changed? Why?
parseUnsignedPayload
util function to parse the unsigned payloadsQualified Impact