Skip to content

Commit

Permalink
Fix original bug concerning blocks and transactions with adding two a…
Browse files Browse the repository at this point in the history
…dapters
  • Loading branch information
tuncpolat committed Aug 28, 2023
1 parent 85d8527 commit 661d9d4
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
public class EthereumDataSource extends DataSource {

public static final String SCHEMA_NAME = "public";
@Getter
private final boolean eventDataRetrieval;
private String clientURL;
@Getter
Expand Down Expand Up @@ -339,6 +340,7 @@ private void createExportedColumnsForEvents( Map<String, List<ExportedColumn>> m
String eventName = event.getString( "name" ); // to match it later with catalogTable.name
String compositeKey = contractName + "_" + eventName; // e.g. Uni_Transfer & Dai_Transfer
JSONArray abiInputs = event.getJSONArray( "inputs" ); // indexed and non-indexed values (topics + data)

eventDataMap.put( compositeKey.toLowerCase(), new EventData( eventName, contractName, address, abiInputs ) );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ public BlockReader makeReader( String clientUrl, int blocks, Predicate<BigIntege
return new EventDataReader( clientUrl, blocks, blockNumberPredicate, contractAddress, fromBlock, toBlock, event ); // Event Data;
}

// maybe I will need a new "makeEventReader"
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.polypheny.db.algebra.type.AlgDataType;
import org.polypheny.db.algebra.type.AlgDataTypeFactory;
import org.polypheny.db.algebra.type.AlgDataTypeImpl;
Expand All @@ -35,6 +36,7 @@
import org.polypheny.db.type.PolyTypeFactoryImpl;
import org.polypheny.db.util.Util;

@Slf4j
public class EthereumSchema extends AbstractSchema {

private final String clientUrl;
Expand All @@ -60,21 +62,31 @@ public Table createBlockchainTable( CatalogTable catalogTable, List<CatalogColum
}

int[] fields = fieldIds.stream().mapToInt( i -> i ).toArray();
EthereumMapper mapper = catalogTable.name.equals( "block" ) ? EthereumMapper.BLOCK : catalogTable.name.equals( "transaction" ) ? EthereumMapper.TRANSACTION : EthereumMapper.EVENTDATA; // Event Data; add EVENTDATA
EthereumMapper mapper = catalogTable.name.startsWith( "block" ) ? EthereumMapper.BLOCK : catalogTable.name.startsWith( "transaction" ) ? EthereumMapper.TRANSACTION : EthereumMapper.EVENTDATA;
// each table will get one EthereumTable; send event metadata down here.
EthereumTable table = new EthereumTable(
EthereumTable.Builder tableBuilder = new EthereumTable.Builder(
clientUrl,
AlgDataTypeImpl.proto( fieldInfo.build() ),
fieldTypes,
fields,
mapper,
ethereumDataSource,
catalogTable.id,
ethereumDataSource.getSmartContractAddressFromCatalogTable(catalogTable.name),
ethereumDataSource.getFromBlock(),
ethereumDataSource.getToBlock(),
ethereumDataSource.getEventFromCatalogTable(catalogTable.name)
catalogTable.id
);

log.warn( catalogTable.name );
log.warn( catalogTable.getNamespaceName() );
log.warn( catalogTable.getDatabaseName() );
log.warn( catalogTable.getOwnerName() );
Boolean eventDataRetrieval = false; //ethereumDataSource.getEventDataRetrieval();
if (eventDataRetrieval) {
tableBuilder
.contractAddress(ethereumDataSource.getSmartContractAddressFromCatalogTable(catalogTable.name))
.fromBlock(ethereumDataSource.getFromBlock())
.toBlock(ethereumDataSource.getToBlock())
.event(ethereumDataSource.getEventFromCatalogTable(catalogTable.name));
}
EthereumTable table = tableBuilder.build();
tableMap.put( catalogTable.name, table );
return table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,82 @@ public class EthereumTable extends AbstractTable implements FilterableTable {
protected final Event event;


public EthereumTable(
String clientUrl,
AlgProtoDataType protoRowType,
List<EthereumFieldType> fieldTypes,
int[] fields,
EthereumMapper mapper,
EthereumDataSource ethereumDataSource,
Long tableId,
String contractAddress,
BigInteger fromBlock,
BigInteger toBlock,
Event event ) {

this.clientUrl = clientUrl;
this.protoRowType = protoRowType;
this.fieldTypes = fieldTypes;
this.fields = fields;
this.ethereumDataSource = ethereumDataSource;
this.mapper = mapper;
this.tableId = tableId;
this.contractAddress = contractAddress;
this.fromBlock = fromBlock;
this.toBlock = toBlock;
this.event = event;
public EthereumTable( Builder builder ) {
this.clientUrl = builder.clientUrl;
this.protoRowType = builder.protoRowType;
this.fieldTypes = builder.fieldTypes;
this.fields = builder.fields;
this.ethereumDataSource = builder.ethereumDataSource;
this.mapper = builder.mapper;
this.tableId = builder.tableId;
this.contractAddress = builder.contractAddress;
this.fromBlock = builder.fromBlock;
this.toBlock = builder.toBlock;
this.event = builder.event;
}


public static class Builder {

protected final String clientUrl;
protected final AlgProtoDataType protoRowType;
protected final int[] fields;
protected final EthereumDataSource ethereumDataSource;
protected final EthereumMapper mapper;
protected List<EthereumFieldType> fieldTypes;
protected Long tableId;

private String contractAddress = null;
private BigInteger fromBlock = null;
private BigInteger toBlock = null;
private Event event = null;


public Builder( String clientUrl,
AlgProtoDataType protoRowType,
List<EthereumFieldType> fieldTypes,
int[] fields,
EthereumMapper mapper,
EthereumDataSource ethereumDataSource,
Long tableId ) {
this.clientUrl = clientUrl;
this.protoRowType = protoRowType;
this.fieldTypes = fieldTypes;
this.fields = fields;
this.ethereumDataSource = ethereumDataSource;
this.mapper = mapper;
this.tableId = tableId;
}


public Builder contractAddress( String val ) {
this.contractAddress = val;
return this;
}


public Builder fromBlock( BigInteger val ) {
this.fromBlock = val;
return this;
}


public Builder toBlock( BigInteger val ) {
this.toBlock = val;
return this;
}


public Builder event( Event val ) {
this.event = val;
return this;
}


public EthereumTable build() {
return new EthereumTable( this );
}

}


Expand Down Expand Up @@ -117,11 +169,11 @@ public Enumerator<Object> enumerator() {
null,
mapper,
finalBlockNumberPredicate,
(EthereumEnumerator.RowConverter<Object>) EthereumEnumerator.converter( fieldTypes, fields ) ,
(EthereumEnumerator.RowConverter<Object>) EthereumEnumerator.converter( fieldTypes, fields ),
contractAddress,
fromBlock,
toBlock,
event);
event );
}
};
}
Expand All @@ -140,7 +192,7 @@ public Enumerator<Object[]> enumerator() {
contractAddress,
fromBlock,
toBlock,
event);
event );
}
};
}
Expand Down

0 comments on commit 661d9d4

Please sign in to comment.