Skip to content

Commit ce3ba73

Browse files
authored
Merge pull request #93 from meldsun0/besu-plugin
Adding basic Besu Samba plugin project with docs and one json rpc : samba_getVersion
2 parents 4c1c4c5 + 7778acb commit ce3ba73

31 files changed

+1466
-1
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ out/
4343

4444
!gradle/wrapper/gradle-wrapper.jar
4545

46-
db/
46+
db/
47+
.DS_Store

besu-plugin/.gitignore

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
*.bak
2+
*.swp
3+
*.tmp
4+
*~.nib
5+
*.iml
6+
*.launch
7+
*.swp
8+
*.log
9+
*.out
10+
nohup.out
11+
.classpath
12+
.DS_Store
13+
.externalToolBuilders/
14+
.gradle/
15+
.idea/
16+
.loadpath
17+
.metadata
18+
.prefs
19+
.project
20+
.recommenders/
21+
.settings
22+
.springBeans
23+
.vertx
24+
./bin
25+
local.properties
26+
target/
27+
tmp/
28+
build/
29+
out/
30+
site/
31+
/.direnv/
32+
/.envrc
33+
acceptance-tests/bin/

besu-plugin/README.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Besu Samba Plugin
2+
3+
This repository hosts the implementation of the besu-samba plugin.
4+
5+
### Quickstart:
6+
- compile samba-plugin `gradlew installDist`
7+
- run `./gradlew runBesu `
8+
9+
10+
11+
#### CLI options | TBD
12+
13+
| Command Line Argument | Default Value |
14+
|-----------------------|---------------|
15+
| `--samba-xyz` | xyz |
16+
17+
18+
## RPC methods
19+
20+
### Get Version
21+
#### `samba_getVersion`
22+
23+
This endpoint is hardcoded value used for testing the plugin.
24+
25+
```shell
26+
curl --location --request POST 'http://localhost:8545' --data-raw '{
27+
"jsonrpc": "2.0",
28+
"method": "samba_getVersion",
29+
"params": [],
30+
"id": 1
31+
}'
32+
```
33+
34+
#### Result
35+
```json
36+
{
37+
"jsonrpc": "2.0",
38+
"id": 1,
39+
"result": "1.0"
40+
}
41+
```

besu-plugin/build.gradle

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import com.github.jk1.license.filter.LicenseBundleNormalizer
2+
3+
buildscript {
4+
ext {
5+
besuIdentifier = "besu-${besuVersion}"
6+
besuFilename = "${besuIdentifier}.tar.gz"
7+
besuUrl = "${distributionBaseUrl}${besuVersion}/${besuFilename}"
8+
besuPluginsIdentifier = "${distributionIdentifier}-${version}"
9+
besuPluginDir = File.createTempDir("plugins")
10+
}
11+
}
12+
13+
plugins {
14+
id 'java-library'
15+
id 'com.github.jk1.dependency-license-report' version '2.9'
16+
}
17+
18+
version = project.hasProperty('releaseVersion') ? project.getProperty('releaseVersion') : 'snapshot'
19+
20+
21+
licenseReport {
22+
// This is for the allowed-licenses-file in checkLicense Task
23+
// Accepts File, URL or String path to local or remote file
24+
allowedLicensesFile = rootProject.file("gradle/allowed-licenses.json")
25+
26+
excludes = []
27+
28+
// If set to true, then all boms will be excluded from the report
29+
excludeBoms = true
30+
31+
filters = [
32+
new LicenseBundleNormalizer(bundlePath: rootProject.file("gradle/license-normalizer-bundle.json"))
33+
]
34+
}
35+
36+
build {
37+
dependsOn checkLicense
38+
}
39+
40+
jar {
41+
enabled = false
42+
}
43+
44+
def imageName = "besu-samba-plugin:latest"
45+
def containerName = "besu-samba-plugin"
46+
47+
48+
49+
task runBesu{
50+
group = "docker"
51+
description = "Builds the Docker image and runs the container"
52+
53+
doLast {
54+
exec {
55+
commandLine "docker", "build", "-t", imageName, "-f", "docker/Dockerfile", "."
56+
}
57+
exec {
58+
commandLine "docker", "rm", "-f", containerName
59+
ignoreExitValue true // Ignore errors if container doesn't exist
60+
}
61+
exec {
62+
commandLine "docker", "run", "-d", "--name", containerName, "-p", "8545:8545", "-p", "9545:9545", imageName
63+
}
64+
}
65+
}
66+
67+
task stopAndRemoveBesu {
68+
group = "docker"
69+
description = "Stops and removes the running Docker container"
70+
71+
doLast {
72+
exec {
73+
commandLine "docker", "stop", containerName
74+
ignoreExitValue true
75+
}
76+
exec {
77+
commandLine "docker", "rm", containerName
78+
ignoreExitValue true
79+
}
80+
}
81+
}
82+
83+
////>>
84+
//task createDistributionTar(type: Tar) {
85+
// dependsOn ':core:jar' // Ensure the JAR is built before creating the tar
86+
//
87+
// archiveBaseName.set("besu-samba-plugin")
88+
// archiveVersion.set(rootProject.version)
89+
// compression = Compression.GZIP
90+
// destinationDirectory.set(rootProject.layout.buildDirectory.dir("distribution"))
91+
//
92+
// from("${rootProject.projectDir}/core/build/libs") {
93+
// include "*.jar"
94+
// }
95+
//}
96+
//
97+
//tasks.build.dependsOn createDistributionTar

besu-plugin/buildSrc/build.gradle

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
plugins {
2+
id 'groovy-gradle-plugin'
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}
8+
9+
dependencies {
10+
implementation 'io.freefair.gradle:lombok-plugin:8.6'
11+
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.25.0'
12+
implementation 'com.github.ben-manes:gradle-versions-plugin:0.51.0'
13+
implementation 'com.github.hierynomus.license:com.github.hierynomus.license.gradle.plugin:0.16.1'
14+
implementation 'io.spring.dependency-management:io.spring.dependency-management.gradle.plugin:1.1.5'
15+
implementation 'de.undercouch.download:de.undercouch.download.gradle.plugin:5.6.0'
16+
}
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import groovy.io.FileType
2+
import org.gradle.api.DefaultTask
3+
import org.gradle.api.tasks.Input
4+
import org.gradle.api.tasks.TaskAction
5+
import org.gradle.tooling.BuildException
6+
7+
class CheckSpdxHeader extends DefaultTask {
8+
private String rootPath
9+
private String spdxHeader
10+
private String filesRegex
11+
private String excludeRegex
12+
13+
@Input
14+
String getRootPath() {
15+
return rootPath
16+
}
17+
18+
void setRootPath(final String rootPath) {
19+
this.rootPath = rootPath
20+
}
21+
22+
@Input
23+
String getSpdxHeader() {
24+
return spdxHeader
25+
}
26+
27+
void setSpdxHeader(final String spdxHeader) {
28+
this.spdxHeader = spdxHeader
29+
}
30+
31+
@Input
32+
String getFilesRegex() {
33+
return filesRegex
34+
}
35+
36+
void setFilesRegex(final String filesRegex) {
37+
this.filesRegex = filesRegex
38+
}
39+
40+
@Input
41+
String getExcludeRegex() {
42+
return excludeRegex
43+
}
44+
45+
void setExcludeRegex(final String excludeRegex) {
46+
this.excludeRegex = excludeRegex
47+
}
48+
49+
@TaskAction
50+
void checkHeaders() {
51+
def filesWithoutHeader = []
52+
53+
new File(rootPath).traverse(
54+
type: FileType.FILES,
55+
nameFilter: ~/${filesRegex}/,
56+
excludeFilter: ~/${excludeRegex}/
57+
) {
58+
f ->
59+
if (!f.getText().contains(spdxHeader)) {
60+
filesWithoutHeader.add(f)
61+
}
62+
}
63+
64+
if (!filesWithoutHeader.isEmpty()) {
65+
throw new BuildException("Files without headers: " + filesWithoutHeader.join('\n'), null)
66+
}
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'io.freefair.lombok'
3+
id 'com.diffplug.spotless'
4+
id 'com.github.ben-manes.versions'
5+
id 'io.spring.dependency-management'
6+
id "de.undercouch.download"
7+
}

besu-plugin/core/build.gradle

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
plugins {
2+
id 'java'
3+
id 'java-library-distribution'
4+
id 'common-plugins'
5+
id 'de.undercouch.download'
6+
}
7+
8+
group = 'samba.besu-plugin'
9+
10+
apply from: rootProject.file("gradle/java.gradle")
11+
apply from: rootProject.file("gradle/dependency-management.gradle")
12+
apply from: rootProject.file('gradle/common-dependencies.gradle')
13+
apply from: rootProject.file("gradle/tests.gradle")
14+
apply from: rootProject.file("gradle/build-aliases.gradle")
15+
apply from: rootProject.file("gradle/lint.gradle")
16+
17+
18+
dependencies {
19+
// annotationProcessor generates the file META-INF/services/org.hyperledger.besu.plugin.BesuPlugin
20+
annotationProcessor 'com.google.auto.service:auto-service'
21+
compileOnly 'com.google.auto.service:auto-service'
22+
23+
implementation project(':service')
24+
25+
implementation "${besuArtifactGroup}:besu-datatypes"
26+
implementation "${besuArtifactGroup}:plugin-api"
27+
implementation "${besuArtifactGroup}.internal:api"
28+
implementation "${besuArtifactGroup}.internal:core"
29+
implementation "org.hyperledger.besu.internal:core:besuInternal"
30+
31+
implementation 'com.google.code.gson:gson'
32+
33+
implementation 'io.tmio:tuweni-bytes'
34+
implementation 'io.tmio:tuweni-units'
35+
implementation 'io.tmio:tuweni-toml'
36+
37+
implementation 'info.picocli:picocli'
38+
39+
// testImplementation "${besuArtifactGroup}.internal:besu"
40+
// testImplementation group: "${besuArtifactGroup}.internal", name: "core", classifier: "test-support"
41+
// testImplementation 'org.awaitility:awaitility'
42+
}
43+
44+
test {
45+
useJUnitPlatform()
46+
}
47+
48+
apply from: rootProject.file("gradle/dist.gradle")
49+
50+
////>>
51+
//jar {
52+
// archiveBaseName.set("besu-samba-plugin")
53+
// archiveVersion.set(rootProject.version)
54+
//
55+
// from {
56+
// configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
57+
// }
58+
// from sourceSets.main.output // Include compiled classes from core
59+
// from project(':service').sourceSets.main.output // Include compiled classes from service
60+
//}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package api;
2+
3+
4+
import org.hyperledger.besu.datatypes.Hash;
5+
import org.hyperledger.besu.ethereum.core.BlockHeader;
6+
import org.hyperledger.besu.ethereum.core.BlockBody;
7+
import org.hyperledger.besu.ethereum.core.TransactionReceipt;
8+
import org.hyperledger.besu.plugin.Unstable;
9+
10+
import org.hyperledger.besu.plugin.services.BesuService;
11+
12+
13+
@Unstable
14+
public interface HistoryService extends BesuService {
15+
16+
BlockHeader getBlockHeaderByBlockHash(Hash blockHash);
17+
18+
BlockBody getBlockBodyByBlockHash(Hash blockHash);
19+
20+
TransactionReceipt getReceiptByBlockHash(Hash blockHash);
21+
22+
BlockHeader getBlockHeaderByBlockNumber(long blockNumber);
23+
24+
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package api;
2+
3+
public interface PortalSambaService {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package rpc;
2+
3+
import org.hyperledger.besu.plugin.services.rpc.PluginRpcRequest;
4+
5+
public interface PluginRpcMethod {
6+
7+
String getNamespace();
8+
9+
String getName();
10+
11+
Object execute(PluginRpcRequest rpcRequest);
12+
}

0 commit comments

Comments
 (0)