This script currently (on a polling loop every ~1 second):
block
table in postgres to find last_processed_block
latest_block_height
last_processed_block
and latest_block_height
, running process_block()
to index each block into postgres
block
, tx
, msg
, msg_event
, msg_event_attr
Keeping "retirements table" as our use case in mind…
Want to write to a table that looks like:
Table name: retirements
Required data field Location in GetTxsEvent
1 retirement date (Postgresql/block)
2 project id (Postgresql/msg_event_attr for newer batch_ids, otherwise REST API)
3 batch id (postgresql/msg_event_attr)
4 credit class id (postgresql/msg_event_attr)
5 amount retired (postgresql/msg_event_attr)
6 issuer of the batch (REST API request)
7 batch start date (postgresql/msg_event_attr)
8 batch end date (postgresql/msg_event_attr)
9 retirement location (postgresql/msg_event_attr)
10 project location (REST API request)
11 retired by (postgresql/msg_event_attr)
12 retirement reason (postgresql, tx.memo or event)
Three approaches:
retirements
table that sources data from postgres and REST API on every row that is writtenevent_retire
which is a pure SQL ETL (INSERT INTO SELECT
)retirements
which polls new rows in event_retire
and joins them with extra data from a REST API to populate retirements
tableretirements
table sourcing only from postgres, and all non tx/event data is queried from the clientIn any above case, we will need to answer questions like:
last_processed
table, which store "table_name" and last processed block height for each ETL process ORExample SQL that can help us generate some kind of table:
INSERT INTO SELECT
chain_num, block_height, tx_idx, msg_idx,
MAX(CASE WHEN key = 'owner' THEN value ELSE null END) as owner,
MAX(CASE WHEN key = 'batch_denom' THEN value ELSE null END) as batch_denom,
MAX(CASE WHEN key = 'amount' THEN value ELSE null END) as amount,
MAX(CASE WHEN key = 'jurisdiction' THEN value ELSE null END) as jurisdiction,
MAX(CASE WHEN key = 'reason' THEN value ELSE null END) as reason,
(SUM(CASE WHEN key = 'amount' THEN 1 ELSE 0 END) > 1) has_duplicates
from msg_event_attr
where type like 'regen.ecocredit.v1.EventRetire'
AND block_height >= '$START_HEIGHT'
AND block_height < '$END_HEIGHT'
group by 1,2,3,4
{“@id”: “https://dev.app.regen.network/project/C61-001”,“@type”: “regen:Project-Page”,“@context”: {“regen”: “https://schema.regen.network#”,“schema”: “http://schema.org/”,“schema:url”: {“@type”: “schema:URL”},“regen:videoURL”: {“@type”: “schema:URL”},“regen:galleryPhotos”: {“@container”: “@list”}},“regen:story”: “Serving as a vehicle for youth education and development, the Youth Farm at Hilltop Urban Farm engages school-aged children from the Hilltop communities with food production and teamwork. Partnering with the Pittsburgh Arlington School, Lighthouse Cathedral, and the New Academy Charter School, the Youth Farm acts as a living agricultural and ecological laboratory for children. It promotes the teaching of Nutrition & Cooking, Growing Food, Local Food Systems, Agriculture as a Career Pathway, and Ecology of Western Pennsylvania through the lens of urban farming with the support of program partners Penn State Extension, Allegheny Land Trust Education Department, Power Up, and Grow Pittsburgh.\n\nAll elements of the Youth Farm are visually appealing, colorful, child-friendly and scaled to size. Children can expect to learn, play and interact among raised bed growing areas, youth gardens, a youth orchard and a youth food forest.\n\nOrchards\n\nPRODUCTION ORCHARD\nHilltop Urban Farm planted the largest orchard in the City of Pittsburgh on May 4th, 2019. The one-acre orchard features 175 fruit and nut trees, including Apricot, Elderberry, Apple, Hazelnut, Cherry, Peach, Pear, Asian Pear, Nectarine, and Fig. The orchard planting was a partnership with The Fruit Tree Planting Foundation and Plant Five for Life. Within the orchard, Hilltop Urban Farm has planted 52 cider trees in partnership with Threadbare Cider House, a local cider house and meadery in Pittsburgh’s Spring Garden neighborhood. \n\nYOUTH FARM ORCHARD\nIn May 2018, Hilltop Urban Farm planted 47 fruit trees to establish the Youth Farm orchard. In September 2018, Hilltop Urban Farm planted 20 restoration chestnut trees with the support of the American Chestnut Planting Foundation and Penn State University College of Agricultural Sciences.”,“regen:storyMedia”: {“@type”: “schema:VideoObject”,“schema:url”: “”,“schema:creditText”: “”},“regen:storyTitle”: “The City of Pittsburgh’s Largest Urban Youth Farm & Orchard”,“regen:previewPhoto”: {“schema:url”: “https://regen-registry.s3.amazonaws.com/projects/ab0f2f60-2555-11ee-b3f2-0267c2be097b/1689676363823-IMG-0845-1560895140.jpeg”,“schema:creditText”: “Hilltop Urban Farm”},“schema:description”: "The Youth Orchard Advisory exists to serve the strategic needs of the Youth Farm and Youth Orchard programs at Hilltop Urban Farm, in Pittsburgh, PA, USA, ensuring community-centric education programming and climate-resilient stewardship of the urban orchard. ",“regen:creditClassId”: “C61”,“regen:galleryPhotos”: [{“schema:url”: “https://regen-registry.s3.amazonaws.com/projects/ab0f2f60-2555-11ee-b3f2-0267c2be097b/1689676396561-DSC_0108.jpeg”,“schema:caption”: “Volunteer plant the Youth Orchard in 2018.”,“schema:creditText”: “Hilltop Urban Farm”},{“schema:url”: “https://regen-registry.s3.amazonaws.com/projects/ab0f2f60-2555-11ee-b3f2-0267c2be097b/1689676477636-65657951_396989047585448_8421597480591818752_n.jpeg”,“schema:caption”: “Children learning cooking lesson at the Youth Farm, from produce they grew in the gardens.”,“schema:creditText”: “Hilltop Urban Farm”}]}
Aug 22, 2023{“@type”: “regen:CreditClass”,“@context”: {“xsd”: “http://www.w3.org/2001/XMLSchema#”,“regen”: “https://schema.regen.network#”,“schema”: “http://schema.org/”,“schema:url”: {“@type”: “schema:URL”},“regen:coBenefits”: {“@container”: “@list”},“regen:measuredGHGs”: {“@container”: “@list”},“regen:creditingTerm”: {“@type”: “schema:activityDuration”},“regen:ecosystemType”: {“@container”: “@list”},“regen:sectoralScope”: {“@container”: “@list”},“regen:lookbackPeriod”: {“@type”: “schema:activityDuration”},“regen:leakageApproach”: {“@container”: “@list”},“regen:permanencePeriod”: {“@type”: “schema:activityDuration”},“schema:itemListElement”: {“@container”: “@list”},“regen:landOwnershipType”: {“@container”: “@list”},“regen:eligibleActivities”: {“@container”: “@list”},“regen:monitoringFrequency”: {“@type”: “schema:frequency”},“regen:verificationMethods”: {“@container”: “@list”},“regen:additionalityApproach”: {“@container”: “@list”},“regen:verificationFrequency”: {“@type”: “schema:frequency”},“regen:offsetGenerationMethod”: {“@container”: “@list”}},“schema:url”: “link to the credit class document”,“schema:name”: “name of the credit class”,“schema:image”: “url of an banner image for the credit class”,“regen:coBenefits”: [],“regen:measuredGHGs”: [],“schema:description”: “”,“regen:creditingTerm”: “”“regen:ecosystemType”: [],“regen:sectoralScope”: [],“regen:lookbackPeriod”: “”,“regen:leakageApproach”: [],“regen:permanencePeriod”: “”,“regen:landOwnershipType”: [],“regen:aggregatedProjects”: {true OR false},“regen:eligibleActivities”: [],“regen:monitoringFrequency”: “”,“regen:verificationMethods”: [],“regen:additionalityApproach”: [],“regen:approvedMethodologies”: {“@type”: “schema:ItemList”,“schema:url”: “”,“schema:itemListElement”: [{“schema:url”: “”,“schema:name”: “”,“schema:version”: “”,“schema:identifier”: “”}]},“regen:verificationFrequency”: “”,“regen:offsetGenerationMethod”: [],“regen:geographicApplicability”: “”}
Aug 7, 2023{“@type”: “regen:C04-CreditClass”,“@context”: {“xsd”: “http://www.w3.org/2001/XMLSchema#”,“regen”: “https://schema.regen.network#”,“schema”: “http://schema.org/”,“schema:url”: {“@type”: “schema:URL”},“regen:coBenefits”: {“@container”: “@list”},“regen:measuredGHGs”: {“@container”: “@list”},“regen:creditingTerm”: {“@type”: “schema:activityDuration”},“regen:ecosystemType”: {“@container”: “@list”},“regen:sectoralScope”: {“@container”: “@list”},“regen:lookbackPeriod”: {“@type”: “schema:activityDuration”},“regen:leakageApproach”: {“@container”: “@list”},“regen:permanencePeriod”: {“@type”: “schema:activityDuration”},“schema:itemListElement”: {“@container”: “@list”},“regen:landOwnershipType”: {“@container”: “@list”},“regen:eligibleActivities”: {“@container”: “@list”},“regen:monitoringFrequency”: {“@type”: “schema:frequency”},“regen:verificationMethods”: {“@container”: “@list”},“regen:additionalityApproach”: {“@container”: “@list”},“regen:verificationFrequency”: {“@type”: “schema:frequency”},“regen:offsetGenerationMethod”: {“@container”: “@list”}},“schema:url”: “https://library.regen.network/v/regen-registry-credit-classes/regen-registry-credit-classes-1/ruuts-credit-class-for-soil-carbon-sequestration-through-regenerative-grazing”,“schema:name”: “Ruuts Credit Class for Soil Carbon Sequestration through Regenerative Grazing”,“regen:coBenefits”: [“Water Infultration”,“Biodiversity”],“regen:measuredGHGs”: [“Carbon Dioxide (CO2)”,“Nitrous Oxide (NO2)”,“Methane (CH4)”],“schema:description”: “The Credit Class and its accompanying methodology provide farmers with a measuring and monitoring process for soil organic carbon sequestration in regenerative grazing systems, enabling them to generate carbon credits that also include robust ecological co-benefits such as water infiltration and biodiversity.”,“regen:creditingTerm”: “P10Y”,“regen:ecosystemType”: [“Pasture”,“Native Grasslands”,“Integrated Cro-Livestock (ICL)”],“regen:sectoralScope”: [“Livestock & Manure Management”],“regen:lookbackPeriod”: “P-14Y”,“regen:sourceRegistry”: {“schema:url”: “https://library.regen.network/v/regen-registry-guide/”,“schema:name”: “Regen Registry”},“regen:leakageApproach”: [“Activity Shifting Leakage”],“regen:permanencePeriod”: “P20Y”,“regen:landOwnershipType”: [“Public”,“Private”],“regen:aggregatedProjects”: true,“regen:bufferPoolAccounts”: {“@type”: “schema:ItemList”,“schema:itemListElement”: [{“schema:name”: “Credit Class (Pooled) Buffer Pool”,“regen:walletAddress”: “regen17pmq7hp4upvmmveqexzuhzu64v36re3w3447n7dt46uwp594wtpsuuh7f6”,“regen:poolAllocation”: “5%”}]},“regen:eligibleActivities”: [“Improved Grazing”,“Rotational Grazing”],“regen:monitoringFrequency”: “Annual”,“regen:verificationMethods”: [“Ruuts Internal Quality Assurance”,“Third-Party ISO 14064-3 Verification”],“regen:additionalityApproach”: [“Common Practice Analysis”,“Regulatory Additionality”],“regen:approvedMethodologies”: {“@type”: “schema:ItemList”,“schema:url”: “”,“schema:itemListElement”: [{“schema:url”: “https://library.regen.network/v/methodology-library/published-methodologies/ruuts-methodology-for-soil-carbon-sequestration”,“schema:name”: “Ruuts Protocol Soil Carbon Sequestration Methodology v1”,“schema:version”: “V1.0”,“schema:identifier”: “”}]},“regen:verificationFrequency”: “Five year”,“regen:offsetGenerationMethod”: [“Carbon Removal”],“regen:geographicApplicability”: “Global”}
Aug 7, 2023Ensure you have regen-ledger checked out at v5.0.0 Clone github.com/regen-network/cosmos-sdk into the parent directory of regen-ledger, and check out v0.46.7-regen-2 Update regen-ledger's go.mod: --- a/go.mod +++ b/go.mod @@ -170,7 +170,7 @@ require ( replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
Jun 14, 2023or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up