1- import { json , Bytes , dataSource } from '@graphprotocol/graph-ts'
1+ import { json , Bytes , dataSource , log } from '@graphprotocol/graph-ts'
22import { IpnftMetadata } from '../generated/schema'
33
44export function handleMetadata ( content : Bytes ) : void {
@@ -9,14 +9,78 @@ export function handleMetadata(content: Bytes): void {
99 const description = value . get ( 'description' )
1010 const externalURL = value . get ( 'external_url' )
1111
12+ let ipnftMetadata = new IpnftMetadata ( dataSource . stringParam ( ) )
13+
1214 if ( name && image && description && externalURL ) {
13- let ipnftMetadata = new IpnftMetadata ( dataSource . stringParam ( ) )
1415 ipnftMetadata . name = name . toString ( )
1516 ipnftMetadata . image = image . toString ( )
1617 ipnftMetadata . externalURL = externalURL . toString ( )
1718 ipnftMetadata . description = description . toString ( )
19+
1820 ipnftMetadata . save ( )
21+ } else {
22+ log . info ( "[handlemetadata] name, image, description, external_url not found" , [ ] )
1923 }
24+
25+ let _properties = value . get ( 'properties' )
26+ if ( _properties ) {
27+ let properties = _properties . toObject ( )
28+ let _initial_symbol = properties . get ( 'initial_symbol' )
29+ if ( _initial_symbol ) {
30+ ipnftMetadata . initialSymbol = _initial_symbol . toString ( )
31+ } else {
32+ ipnftMetadata . initialSymbol = ""
33+ log . info ( "[handlemetadata] initial_symbol not found" , [ ] )
34+ }
35+
36+ let _project_details = properties . get ( 'project_details' )
37+
38+ if ( _project_details ) {
39+ let projectDetails = _project_details . toObject ( )
40+
41+ let _organization = projectDetails . get ( 'organization' )
42+ if ( _organization ) {
43+ ipnftMetadata . organization = _organization . toString ( )
44+ }
2045
46+ let _topic = projectDetails . get ( 'topic' )
47+ if ( _topic ) {
48+ ipnftMetadata . topic = _topic . toString ( )
49+ }
50+
51+ let _research_lead = projectDetails . get ( 'research_lead' )
52+
53+ if ( _research_lead ) {
54+ let researchLead = _research_lead . toObject ( )
55+ let researchLead_email = researchLead . get ( 'email' )
56+ let researchLead_name = researchLead . get ( 'name' )
57+
58+ if ( researchLead_email && researchLead_name ) {
59+ ipnftMetadata . researchLead_email = researchLead_email . toString ( )
60+ ipnftMetadata . researchLead_name = researchLead_name . toString ( )
61+ }
62+ }
63+
64+ let _funding_amount = projectDetails . get ( 'funding_amount' )
65+
66+ if ( _funding_amount ) {
67+ let funding_amount = _funding_amount . toObject ( )
68+ let _fundingAmount_value = funding_amount . get ( 'value' )
69+ let _fundingAmount_decimals = funding_amount . get ( 'decimals' )
70+ let _fundingAmount_currency = funding_amount . get ( 'currency' )
71+ let _fundingAmount_currencyType = funding_amount . get ( 'currency_type' )
72+
73+ if ( _fundingAmount_value && _fundingAmount_decimals && _fundingAmount_currency && _fundingAmount_currencyType ) {
74+ // on json metadata this can be a decimal value. I'm using a string to store as there's imo no f64 compatible decimal type on the schema scalar types
75+ // https://thegraph.com/docs/en/subgraphs/developing/creating/ql-schema/#built-in-scalar-types
76+ ipnftMetadata . fundingAmount_value = _fundingAmount_value . toF64 ( ) . toString ( )
77+ ipnftMetadata . fundingAmount_decimals = i8 ( _fundingAmount_decimals . toI64 ( ) )
78+ ipnftMetadata . fundingAmount_currency = _fundingAmount_currency . toString ( )
79+ ipnftMetadata . fundingAmount_currencyType = _fundingAmount_currencyType . toString ( )
80+ }
81+ }
82+ }
83+ }
84+ ipnftMetadata . save ( )
2185 }
2286}
0 commit comments