-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
PSBT internal transaction property getters #1561
Conversation
Thoughts:
|
How important is it that the getters are enumerable? Maybe I'm missing something but it seems a bit awkward to get working with getters. If we do We can just not use the nice get/set syntax and instead define them in constructor()
Object.defineProperty(this, 'version', {
enumerable: true,
get: (): number => this.__CACHE.__TX.version,
set: (version: number): Psbt => this.setVersion(version),
});
} This works, However this confuses TypeScript. It doesn't understand what's happening in We can fix TypeScript by first creating a property and setting a random value of the correct type so it can understand what's going on, then overwriting that definition in the constructor to what we actually want with version: number = 0;
constructor()
Object.defineProperty(this, 'version', {
enumerable: true,
get: (): number => this.__CACHE.__TX.version,
set: (version: number): Psbt => this.setVersion(version),
});
} It feels pretty hacky and we need to do that for each property. We're just tricking TypeScript into thinking it knows what's going on, we could be returning any other type from the getter and it wouldn't realise. It's also causing errors in the |
Yeah, forget about that part. |
This PR exposes some properties of the transaction internal to the PSBT in a readonly way that prevents mutation.
One issue is that it's a little confusing that we now have two sets of
inputs
/outputs
arrays. One for the PSBT data and one for the internal transaction data:Maybe that's ok or maybe we should call it
psbt.txInputs
to make it a little clearer?