-
Notifications
You must be signed in to change notification settings - Fork 1
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
Read a contract as State
#50
Conversation
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.
I have only a few small comments. Apart from that, the code seems to be doing what it is supposed to do. It should be good enough for MVP. Let's merge it
function isResponse(data: unknown): boolean { | ||
if (typeof data === 'object' && data !== null) { | ||
const maybe = data as Response | ||
if (typeof maybe['jsonrpc'] !== 'string') return false | ||
if (typeof maybe['id'] !== 'number') return false | ||
const res = maybe['result'] | ||
if (typeof res !== 'object') return false | ||
if (typeof res['latestLedger'] !== 'number') return false | ||
const entries = res['entries'] | ||
if (!Array.isArray(entries)) return false | ||
|
||
return !entries.some((e) => { | ||
if (typeof e['key'] !== 'string') return true | ||
if (typeof e['xdr'] !== 'string') return true | ||
if (typeof e['lastModifiedLedgerSeq'] !== 'number') return true | ||
return false | ||
}) | ||
} else return false | ||
} |
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.
I feel like this could be rewritten, but this is definitely not a show-stopper for stopping this PR from being merged
new xdr.LedgerKeyContractData({ | ||
contract: new Address(contractId).toScAddress(), | ||
key: xdr.ScVal.scvSymbol(symbolText), | ||
durability: xdr.ContractDataDurability.persistent(), |
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.
Just a note: this method only works for persistent fields. Perhaps, it's worth adding a comment
return V.i64((v.value() as xdr.Int64).toBigInt()) | ||
case xdr.ScValType.scvU128(): { | ||
const cast = v.value() as xdr.UInt128Parts | ||
const hiInt = cast.hi().toBigInt() * 2n ** 64n |
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.
const hiInt = cast.hi().toBigInt() * 2n ** 64n | |
const hiInt = cast.hi().toBigInt() * (2n ** 64n) |
There is no bug here. I had to lookup the precedence of *
and **
, so it would be better to have it explicit
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.
I had parenthesis initially, and I think the liter or the formatter actually removed them
The test is failing though. @Kukovec do you know what is happening? |
No clue, it's not the actual tests in the code, but the solarkraft build itself. The error messages are pretty unhelpful ( |
it looks like you do not have |
Looking at the reported error, I had to fix the missing dependency:
After doing that, I am getting exactly the same error message, as Github is reporting. |
I guess, the issue is that we are compiling the project with nodejs, whereas |
There were several reasons for the test not going through:
|
Since the test is passing now, I will merge the PR, so we are not blocked with further development |
closes #49
Adds the following:
State
conversion