Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
6d6e407d
Commit
6d6e407d
authored
Feb 28, 2023
by
Will Cory
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
comments
parent
86904fb2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
19 deletions
+23
-19
write.ts
packages/atst/src/commands/write.ts
+2
-19
castAsDataType.ts
packages/atst/src/lib/castAsDataType.ts
+21
-0
No files found.
packages/atst/src/commands/write.ts
View file @
6d6e407d
...
...
@@ -9,6 +9,7 @@ import { ATTESTATION_STATION_ADDRESS } from '../constants/attestationStationAddr
import
{
DEFAULT_RPC_URL
}
from
'
../constants/defaultRpcUrl
'
import
{
prepareWriteAttestation
}
from
'
../lib/prepareWriteAttestation
'
import
{
writeAttestation
}
from
'
../lib/writeAttestation
'
import
{
castAsDataType
}
from
'
../lib/castAsDataType
'
import
{
dataTypeOptionValidator
}
from
'
../types/DataTypeOption
'
const
zodAddress
=
()
=>
...
...
@@ -82,29 +83,11 @@ export const write = async (options: WriteOptions) => {
}),
})
const
castAsDataType
=
(
value
:
any
)
=>
{
if
(
parsedOptions
.
dataType
===
'
string
'
)
{
return
value
}
else
if
(
parsedOptions
.
dataType
===
'
number
'
)
{
return
Number
(
value
)
}
else
if
(
parsedOptions
.
dataType
===
'
bool
'
)
{
return
Boolean
(
value
)
}
else
if
(
parsedOptions
.
dataType
===
'
bytes
'
)
{
return
value
}
else
if
(
parsedOptions
.
dataType
===
'
address
'
)
{
return
value
}
else
{
throw
new
Error
(
`Unrecognized data type
${
parsedOptions
.
dataType
satisfies
never
}
`
)
}
}
try
{
const
preparedTx
=
await
prepareWriteAttestation
(
parsedOptions
.
about
,
parsedOptions
.
key
,
castAsDataType
(
parsedOptions
.
value
),
castAsDataType
(
parsedOptions
.
value
,
parsedOptions
.
dataType
),
network
.
chainId
)
const
result
=
await
writeAttestation
(
preparedTx
)
...
...
packages/atst/src/lib/castAsDataType.ts
0 → 100644
View file @
6d6e407d
import
{
DataTypeOption
}
from
'
../types/DataTypeOption
'
/**
* @internal
* Takes a datatype and returns the value casted to that type
*/
export
const
castAsDataType
=
(
value
:
any
,
dataType
:
DataTypeOption
)
=>
{
if
(
dataType
===
'
string
'
)
{
return
value
}
else
if
(
dataType
===
'
number
'
)
{
return
Number
(
value
)
}
else
if
(
dataType
===
'
bool
'
)
{
return
Boolean
(
value
)
}
else
if
(
dataType
===
'
bytes
'
)
{
return
value
}
else
if
(
dataType
===
'
address
'
)
{
return
value
}
else
{
throw
new
Error
(
`Unrecognized data type
${
dataType
satisfies
never
}
`
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment