Skip to content

Commit

Permalink
Adding version displays to OG and OScan
Browse files Browse the repository at this point in the history
  • Loading branch information
otherview committed Sep 27, 2023
1 parent 584b6a7 commit 345a136
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/manual-deploy-obscuro-gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ jobs:
datadog/agent:latest \
&& cd /home/obscuro/go-obscuro/ \
&& docker run -d -p 80:80 -p 81:81 --name ${{env.RESOURCE_STARTING_NAME}}-OG-${{ GITHUB.RUN_NUMBER }} \
-e OBSCURO_GATEWAY_VERSION="${{ GITHUB.RUN_NUMBER }}" \
${{ env.OBSCURO_GATEWAY_BUILD_TAG }} \
./wallet_extension_linux -host=0.0.0.0 -port=80 -portWS=81 -nodeHost=${{ env.OBSCURO_GATEWAY_NODE_HOST }} \
-logPath=sys_out -dbType=mariaDB -dbConnectionURL="obscurouser:${{ secrets.OBSCURO_GATEWAY_MARIADB_USER_PWD }}@tcp(obscurogateway-mariadb-${{ github.event.inputs.testnet_type }}.uksouth.cloudapp.azure.com:3306)/ogdb"'
2 changes: 1 addition & 1 deletion .github/workflows/manual-deploy-obscuro-scan-2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
name: ${{ github.event.inputs.testnet_type }}-fe-obscuro-scan
location: 'uksouth'
restart-policy: 'Never'
environment-variables: VITE_APIHOSTADDRESS=http://${{ github.event.inputs.testnet_type }}-api-obscuro-scan.uksouth.azurecontainer.io
environment-variables: VITE_APIHOSTADDRESS=http://${{ github.event.inputs.testnet_type }}-api-obscuro-scan.uksouth.azurecontainer.io VITE_FE_VERSION=${{ GITHUB.RUN_NUMBER }}
command-line: npm run serve-prod
ports: '80'
cpu: 2
Expand Down
16 changes: 14 additions & 2 deletions tools/obscuroscan_v2/frontend/src/components/BotBarItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,27 @@

<img src="@/assets/imgs/twitter_logo.png" alt="obscu.ro" class="header-image" />
</el-col>
<el-col :span="20" class="version-column">
<div class="version-display">version: {{ version }}</div>
</el-col>
</el-row>
</template>

<script>
import Config from "@/lib/config";
export default {
name: "BotBarItem"
name: "BotBarItem",
computed: {
version() {
return Config.version;
}
}
}
</script>

<style scoped>
.version-column {
text-align: right;
}
</style>
1 change: 1 addition & 0 deletions tools/obscuroscan_v2/frontend/src/lib/config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Config {
static backendServerAddress = "http://127.0.0.1:43910"
static pollingInterval = 1000
static pricePollingInterval = 10000*10000
static version = "dev"
}

export default Config
1 change: 1 addition & 0 deletions tools/obscuroscan_v2/frontend/src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Config {
static backendServerAddress = "http://127.0.0.1:43910"
static pollingInterval = 1000
static pricePollingInterval = 10000*10000
static version = "dev"
}

export default Config
1 change: 1 addition & 0 deletions tools/obscuroscan_v2/frontend/src/lib/config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Config {
static backendServerAddress = import.meta.env.VITE_APIHOSTADDRESS
static pollingInterval = 1000
static pricePollingInterval = 10*this.pollingInterval
static version = import.meta.env.VITE_FE_VERSION
}

export default Config
19 changes: 19 additions & 0 deletions tools/walletextension/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ func NewHTTPRoutes(walletExt *walletextension.WalletExtension) []Route {
Name: common.PathHealth,
Func: httpHandler(walletExt, healthRequestHandler),
},
{
Name: common.PathVersion,
Func: httpHandler(walletExt, versionRequestHandler),
},
}
}

Expand Down Expand Up @@ -440,3 +444,18 @@ func healthRequestHandler(walletExt *walletextension.WalletExtension, userConn u
walletExt.Logger().Error(fmt.Errorf("error writing success response, %w", err).Error())
}
}

// Handles request to /version endpoint.
func versionRequestHandler(walletExt *walletextension.WalletExtension, userConn userconn.UserConn) {
// read the request
_, err := userConn.ReadRequest()
if err != nil {
walletExt.Logger().Error(fmt.Errorf("error reading request: %w", err).Error())
return
}

err = userConn.WriteResponse([]byte(walletExt.Version()))
if err != nil {
walletExt.Logger().Error(fmt.Errorf("error writing success response, %w", err).Error())
}
}
1 change: 1 addition & 0 deletions tools/walletextension/api/staticOG/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ <h2>◠. Obscuro Gateway Demo! ◠.</h2>
</tbody>
</table>

<div id="versionDisplay" style="position: fixed; bottom: 10px; right: 10px;"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions tools/walletextension/api/staticOG/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const pathJoin = obscuroGatewayVersion + "/join/";
const pathAuthenticate = obscuroGatewayVersion + "/authenticate/";
const pathQuery = obscuroGatewayVersion + "/query/";
const pathRevoke = obscuroGatewayVersion + "/revoke/";
const pathVersion = "/version/";
const obscuroChainIDDecimal = 443;
const methodPost = "post";
const methodGet = "get";
Expand All @@ -28,6 +29,26 @@ let obscuroGatewayAddress = window.location.protocol + "//" + window.location.ho

let provider = null;

async function fetchAndDisplayVersion() {
try {
const versionResp = await fetch(
pathVersion, {
method: methodGet,
headers: jsonHeaders,
}
);
if (!versionResp.ok) {
throw new Error("Failed to fetch the version");
}

let response = await versionResp.text();

const versionDiv = document.getElementById("versionDisplay");
versionDiv.textContent = "Version: " + response;
} catch (error) {
console.error("Error fetching the version:", error);
}
}

async function addNetworkToMetaMask(ethereum, userID, chainIDDecimal) {
// add network to MetaMask
Expand Down Expand Up @@ -200,6 +221,10 @@ const initialize = async () => {
// getUserID from the gateway with getStorageAt method
let userID = await getUserID()


// load the current version
await fetchAndDisplayVersion();

// check if userID exists and has a correct type and length (is valid) and display either
// option to join or to add a new account to existing user
if (isValidUserIDFormat(userID)) {
Expand Down
1 change: 1 addition & 0 deletions tools/walletextension/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
GetStorageAtUserIDRequestMethodName = "getUserID"
SuccessMsg = "success"
APIVersion1 = "/v1"
PathVersion = "/version/"
)

var (
Expand Down
9 changes: 8 additions & 1 deletion tools/walletextension/container/walletextension_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"os"

"github.com/ethereum/go-ethereum/common"
"github.com/obscuronet/go-obscuro/go/common/log"
Expand Down Expand Up @@ -78,8 +79,14 @@ func NewWalletExtensionContainerFromConfig(config config.Config, logger gethlog.
}
}

// captures version in the env vars
version := os.Getenv("OBSCURO_GATEWAY_VERSION")
if version == "" {
version = "dev"
}

stopControl := stopcontrol.New()
walletExt := walletextension.New(hostRPCBindAddr, &userAccountManager, databaseStorage, stopControl, logger)
walletExt := walletextension.New(hostRPCBindAddr, &userAccountManager, databaseStorage, stopControl, version, logger)
httpRoutes := api.NewHTTPRoutes(walletExt)
httpServer := api.NewHTTPServer(fmt.Sprintf("%s:%d", config.WalletExtensionHost, config.WalletExtensionPortHTTP), httpRoutes)

Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/main/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
walletExtensionPortWSUsage = "The port on which to serve websocket JSON RPC requests. Default: 3001."

nodeHostName = "nodeHost"
nodeHostDefault = "testnet.obscu.ro"
nodeHostDefault = "erpc.testnet.obscu.ro"
nodeHostUsage = "The host on which to connect to the Obscuro node. Default: `testnet.obscu.ro`."

nodeHTTPPortName = "nodePortHTTP"
Expand Down
7 changes: 7 additions & 0 deletions tools/walletextension/wallet_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ type WalletExtension struct {
storage storage.Storage
logger gethlog.Logger
stopControl *stopcontrol.StopControl
version string
}

func New(
hostAddr string,
userAccountManager *useraccountmanager.UserAccountManager,
storage storage.Storage,
stopControl *stopcontrol.StopControl,
version string,
logger gethlog.Logger,
) *WalletExtension {
return &WalletExtension{
Expand All @@ -53,6 +55,7 @@ func New(
storage: storage,
logger: logger,
stopControl: stopControl,
version: version,
}
}

Expand Down Expand Up @@ -414,3 +417,7 @@ func (w *WalletExtension) checkParametersForInterceptedGetStorageAt(params []int
}
return false
}

func (w *WalletExtension) Version() string {
return w.version
}

0 comments on commit 345a136

Please sign in to comment.