How to build a transaction using bitcoinjs-lib

I’m trying to build a transaction using bitcoinjs-lib.

Here is my last transaction.
https://blockstream.info/api/tx/91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f

{
  "weight" : 705,
  "txid" : "91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f",
  "status" : {
    "block_height" : 795582,
    "block_hash" : "00000000000000000005386018b10cd1cde59d6923fd918757690c004b01c4b8",
    "confirmed" : true,
    "block_time" : 1687529469
  },
  "vin" : [
    {
      "inner_redeemscript_asm" : "OP_0 OP_PUSHBYTES_20 01868bd1fb92e6547438e8bf07a6c08ee0157c8b",
      "txid" : "e0c545a6dfaf1d5bb67f6349190d0653b597bda6585696cf217e55df07b1f190",
      "prevout" : {
        "scriptpubkey_type" : "p2sh",
        "scriptpubkey_address" : "3PA2J9aN9N82q4YZyhBYHBcHpVvpGewvX2",
        "value" : 956656,
        "scriptpubkey_asm" : "OP_HASH160 OP_PUSHBYTES_20 eb762ef1946c2d462764d30112ce27c531fdd603 OP_EQUAL",
        "scriptpubkey" : "a914eb762ef1946c2d462764d30112ce27c531fdd60387"
      },
      "scriptsig_asm" : "OP_PUSHBYTES_22 001401868bd1fb92e6547438e8bf07a6c08ee0157c8b",
      "is_coinbase" : false,
      "vout" : 1,
      "sequence" : 4294967295,
      "witness" : [
        "304402206000ff05c68afd2b2aece9554ef25bae6d7402be96c6eedc866f4ca1dcafe0dd02204dfc8852bd4c4ae2f36cd0f4db82d22e37422b08e7d829f10e5aa9d8ae07d70901",
        "02dba3c42f38c394dd7370884f23bd0dec5373e9d38439915124188f06b6a19395"
      ],
      "scriptsig" : "16001401868bd1fb92e6547438e8bf07a6c08ee0157c8b"
    }
  ],
  "vout" : [
    {
      "scriptpubkey_type" : "v1_p2tr",
      "scriptpubkey_address" : "bc1p7cqr7rhvxy8c69k5ks3qp6h3nq85tskgxd4f0h0mz5g3lvtykgtq4ddhyc",
      "value" : 54980,
      "scriptpubkey_asm" : "OP_PUSHNUM_1 OP_PUSHBYTES_32 f6003f0eec310f8d16d4b42200eaf1980f45c2c8336a97ddfb15111fb164b216",
      "scriptpubkey" : "5120f6003f0eec310f8d16d4b42200eaf1980f45c2c8336a97ddfb15111fb164b216"
    },
    {
      "scriptpubkey_type" : "p2sh",
      "scriptpubkey_address" : "3PA2J9aN9N82q4YZyhBYHBcHpVvpGewvX2",
      "value" : 894242,
      "scriptpubkey_asm" : "OP_HASH160 OP_PUSHBYTES_20 eb762ef1946c2d462764d30112ce27c531fdd603 OP_EQUAL",
      "scriptpubkey" : "a914eb762ef1946c2d462764d30112ce27c531fdd60387"
    }
  ],
  "size" : 258,
  "locktime" : 0,
  "version" : 2,
  "fee" : 7434
}

Here is the code I’m working on. I hardcoded the values here for clarity. What do I use for the redeem script?

const network = bitcoin.networks.bitcoin;
const psbt = new bitcoin.Psbt({ network });

psbt.addInput({
    hash: "91feea5f5c7b67b3e56c0f5d23d6da3065855c23b4cc7dded8efd8ff8065500f",
    index: 1,
    witnessUtxo: {
        script: Buffer.from("a914eb762ef1946c2d462764d30112ce27c531fdd60387", 'hex'),
        value: 894242,
    },
    redeemScript: Buffer.from("???", 'hex'),
});

psbt.addOutput({
    address: to_address,
    value: Math.floor(amount * 1e8),
});

psbt.signInput(0, keyPair);
psbt.finalizeInput(0);
const tx = psbt.extractTransaction();
return tx.toHex();

Javascript with liquid variables [closed]

{% assign sorted_products_unsort = section.settings.collection.products %}


var liquid_var = '{{ sorted_products_unsort }}';
console.log(liquid_var);

I get the “LazyProductDropCollection” I want to change the liquid condition using JavaScript

Showing large .tif file on leaflet map 07.2023

Could someone give me a sample code on how to show large .tiff files as GeoTiff RGB images on the map in the open-source leaflet 1.9.1 map page? I’m struggling with writing code like this, but whenever I try to create something like this, either the map doesn’t play correctly or the file can’t be opened properly because the website in html is not able to open this type of file. I know that Webodm uses leaflet maps, and like them, I would like to have a map where I could see an image in the .tiff extension, taken, for example, from an orthophotomap already created in the webodm program with WGS84 coordinate data.

I have no ideas what I could use to make it work or at least correctly display this file on the page.

why does the input field state is not changing while typing in textField MUI

In my react.js component, when i am trying to start type anything in textField, it is not updating .

I tried with debugger the i found — when first character entered, component re-renderd so looses its prevous states and looks like textField value is not updating.

It was working fine earlier when i was using mui Box instead of Grid, but now removing Grid also is not working .
Same question asked by many people, i went through their provided solution but no luck.

Here is my code :

const Registration = (props: any) => {       

            const [loading, setLoading] = useState(false);
            const [successAlert, setSuccessAlert]=useState(false)
            const [formData, setFormData] = useState({
            firstName:'',
            })
           const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
               event.preventDefault();
               submitRegister()
             };
           
            const submitRegister = async()=>{
             setLoading(true)
             axios.post('example.com/create/user',formData)
             .then(response =>{
               console.log(response.data.code)
               if(response.data.code ===200){
                 setSuccessAlert(true)
                 setLoading(false)
               }
             })
             .catch(error =>{
               console.log(error)
           
             })
           
            }  

            const handleChangeForm=(e:ChangeEvent<HTMLInputElement>)=>{
             const{name ,value }= e.target;
             setFormData((prevFormData)=>({
               ...prevFormData,
               [name]:value
             }));
           };

           const FormContainer = styled("form")(({ theme }) => ({
            maxWidth: 700,
            [theme.breakpoints.down(theme.breakpoints.values.sm)]: {
              maxWidth: 300
            },
            [theme.breakpoints.up(theme.breakpoints.values.md)]: {
              maxWidth: 650
            }
          }));

          const StyledTextField = styled(TextField)(() => ({
            "& .MuiFormLabel-asterisk": {
              color: "red"
            },
            '& label.Mui-focused': {
              color: '#96A8AE', //Dark Grey as per SCM
          },
          '& .MuiOutlinedInput-root': {
              '&.Mui-focused fieldset': {
                  borderColor: '#96A8AE',
              },
          },
          
          }));
               
               return (
                       <Grid container className="registration__container" spacing={2}>
                           <Grid item xs={7} md={7} lg={7} xl={7}>
                             <Grid className='left'>
                               
                               // some code here
                             </Grid>
                             {loading &&<Loader /> }
                           </Grid>
                           <Grid item xs={5} md={5} lg={5} xl={5} className='registration__form' key="regis-form">
                               
                               <FormContainer onSubmit={handleSubmit}>
                                   <Grid item container className='details__form' columnSpacing={{ xs: 2, sm: 2, md: 2 }}>
                                       <Grid item xs={6} md={6} lg={6} xl={6}>
                                           <StyledTextField
                                               label="First Name"
                                               name="firstname"
                                               value={formData.firstName}
                                               onChange={handleChangeForm}
                                               key="firstName"                                    
                                               size='medium'
                                               required
                                               fullWidth
                                             />
                                       </Grid>
                                     </Grid>
               
                                   
                                   <Grid item xs={12} className="submitbtn__wrapper">
                                         <button type="submit">Register</button>
                                   </Grid>
               
                                 </FormContainer>
                           </Grid>
                     </Grid>
                 );
       };
       
       export default Registration;

I also Tried-
React.js – input losing focus when rerendering

React Hooks – Input loses focus when 1 character is typed in

In React ES6, why does the input field lose focus after typing a character?
and other similar question , but did not help me.

How to update cell props programmatically in Mui-Datagrid

We are using Mui-Datagrid component where the users can upload and edit their data.
Within customID column definition, there are the preProcessEditCellProps and renderEditCell properties.

const columns = [ { field: "customID", headerName: "customID", width: 100, editable: true, preProcessEditCellProps: customIDValidation, renderEditCell: renderEditCell } ... ];

The preProcessEditCellProps checking the validity of the input only when the user is typing.
If the length of the value is less than 3 then it returns error & errorMessage and then pass it to renderEditCell as a props.

The thing is that we have a submit button where we want to validate the whole cells before submitting the data and then update the cell props in order to show which cells are invalid and style them as well.

I tried to figure out how to update these cell props using the apiRef of Mui DataGrid and i couldn’t find any suitable method to achieve that.

attached codesandbox:
https://codesandbox.io/s/morning-snow-pmj64y?file=/src/App.js

Any ideas are more than welcome
Thanks!

Rust secp256k1 equivalent of NodeJS `crypto::ECDH::computeSecret()`?

I’ve written this working NodeJS/Javascript function:

/*
 * Calculate the Symmetric Key from the Public and Secret keys from two
 * different key pairs.
 * 
 * Note: symmetric_key(publicA, secretB) == symmetric_key(publicB, secretA)
 */
function symmetric_key(pkey, skey) {
        const ephemeral = crypto.createECDH('secp256k1');
        ephemeral.setPublicKey(pkey);
        const centre = crypto.createECDH('secp256k1');
        centre.setPrivateKey(skey);
        return centre.computeSecret(ephemeral.getPublicKey());
}

I’m trying to understand how I can use the Rust secp256k1 library to do the same.

Looking at secp256k1::SecretKey’s methods I cannot see a direct equivalent.

  • What is that library’s version of computeSecret() called?
  • If it doesn’t have an analogous method, how can I compute the required secret?

Do we have R2DBC support for snowflake?

Do we have R2DBC support for snowflake? or How can we use snowflakes in reactive applications?

do we connect snowflake using ConnectionFactory in springwebflux ?

sample connection:

try {

    ConnectionFactoryOptions baseOptions = ConnectionFactoryOptions.parse(url);
    ConnectionFactoryOptions.Builder ob = ConnectionFactoryOptions.builder()
            .from(baseOptions).option(USER, username)
            .option(PASSWORD, password)
            .option(DRIVER, driver);
    return ConnectionFactories.get(ob.build());

how to pass types as props in a reuseable component

I have a reusable component that i pass rows and headings to it as props where ever i use the component. the only problem i have is how to pass types as props to this component?

here is my reusable component

import { TableCell, TableRow } from "@mui/material";
import TableCellOperations from "./table-cell-operations.componenet";
import { PropertyListItem } from "@slice/properties.slice";

interface Props {
  rows?: PropertyListItem[];
  headings: HeadingsTypes[];
}

export interface HeadingsTypes {
  id: string;
  title: string;
  label: string;
}

const TableRowsComponent: React.FC<Props> = ({ rows, headings }) => {
  return (
    <>
      {rows?.map((row) => (
        <TableRow key={row.id}>
          {headings.map((heading) => (
            <TableCell key={heading.id} align="center">
              {typeof row[heading.id] === "object" && row[heading.id] !== null
                ? row[heading.id]?.title
                : heading.id === "status"
                ? row.status == 0
                  ? "منقضی"
                  : "فعال"
                : row[heading.id]}
            </TableCell>
          ))}
          <TableCellOperations />
        </TableRow>
      ))}
    </>
  );
};

export default TableRowsComponent;

my rows type could be diffrent by situation. in here i put PropertyListItem as rows types but maybe types of rows change. so i want to pass type of rows as a props to this reuseable component. what should i do?

Working with a number of variables at a time in JavaScript

Consider the set of codes I have:

x1=x1.toFixed(prec);
x2=x2.toFixed(prec);
y1=y1.toFixed(prec);
y2=y2.toFixed(prec);
a1=a1.toFixed(prec);
a2=a2.toFixed(prec);
b1=b1.toFixed(prec);
b2=b2.toFixed(prec);
c1=c1.toFixed(prec);
c2=c2.toFixed(prec);

I have these 10 variables already declared and they each contain a float value. Is there any way to apply the function toFixed(prec) with prec as the parameter to all these variables with a shorter code? Using an array or something like that?

Node.js WebRTC Zoom Clone: Videos Unstable with More than 4 Users

I have developed a Zoom clone using Node.js with WebRTC, peerjs and socket io. However, I’m facing stability issues when more than 4 users joins the same room. The video feeds continuously refresh, and sometimes users are unable to see each other in the same room.

I suspect that the issue may be related to either the peer servers or the application load. I would like to understand the possible causes for this problem and how to address it. I also have fully configured stun/turn servers

Here are some additional details:

I am using Node.js for the backend of my Zoom clone application.
WebRTC is employed for establishing peer-to-peer connections between users.
The instability occurs specifically when there are more than 4 users in the same room.
The video feeds refresh frequently, causing disruptions in the user experience.
In some cases, users are unable to see each other’s video feeds altogether.

I have reviewed my code and configurations but have not been able to identify the root cause. I would appreciate any insights, suggestions, or troubleshooting steps that can help resolve this issue. Thank you in advance for your assistance.

How to bundle dependencies of a custom npm package to make it work as one

I’m developing a private npm package in order to have some common utilities shared between projects.

As dependency of this npm package I am using another package as dependency (jest-extended to be precise). After I make sure that my custom package works fine, I bundled it with rollup.js, publish it on a private registry and then download it in the project where I want to use it.

At this point I have the problem that in the project where I downloaded my custom package errors are thrown because there isn’t jest-extended installed in the project. My idea is to have this kind of dependencies inside custom package without installing them manually in projects where I want to install my custom package.

Is it possible to bundle these dependencies in order to use a custom package as a full working standalone one ?

Perfomance issues on navigation through Bottom Navigator

I’m handling darkmode toggling in a react native app and I have to pass the darkmode/lightmode styles as props to screens that are navigated through the BottomTabNavigatorbut the issue is the navigation process from one bottom tab to another is very slow( This has happened after passing the props to those respective screens)

I’m using :

 react-navigation/bottom-tabs": "^6.5.7",
 react-navigation/material-top-tabs": "^6.6.2",
 react-navigation/native": "^6.1.6",
 react-navigation/native-stack": "^6.9.12"  

My BottomTabs.js code

const BottomTabs = () => {
  const { isDarkModeEnabled } = useContext(DarkModeContext);

  const screenStyle = isDarkModeEnabled
    ? {
        backgroundColor: "#050C12",
        color: "#FFFAF0", // Text color for dark mode
        iconColor: "#FFFFFF", // Icon color for dark mode
      }
    : {
        backgroundColor: "#F8F8F8",
        color: "black", // Text color for light mode
        iconColor: "black", // Icon color for light mode
      };

  const tabBarStyle = isDarkModeEnabled
    ? {
        backgroundColor: "#101E2A",
        color: "#FFFAF0", // Text color for dark mode
        iconColor: "#FFFFFF", // Icon color for dark mode
      }
    : {
        backgroundColor: "white",
        color: "black", // Text color for light mode
        iconColor: "black", // Icon color for light mode
      };

  const cardStyle = isDarkModeEnabled
    ? {
        cardBackgroundColor: "#101E2A",
        cardColor: "#FFFAF0",
        cardIconColor: "#D9E6F2",
      }
    : {
        cardBackgroundColor: "white",
        cardColor: "#101010",
        cardIconColor: "#101010",
      };

  const statsCardStyle = isDarkModeEnabled
    ? {
        cardBackgroundColor: "tomato",
        cardColor: "#FFFAF0",
      }
    : {
        cardBackgroundColor: "tomato",
        cardColor: "#101010",
      };

  //popular league card styling on dark mode toggling
  const popularLeagueCardStyle = isDarkModeEnabled
    ? {
        cardBackgroundColor: "#101E2A",
        cardColor: "#FFFAF0",
      }
    : {
        cardBackgroundColor: "white",
      };

  return (
    <BottomTab.Navigator>
   <BottomTab.Screen name="Home" options={{ 
    headerShown: false }}>
        {(props) => (
        <View
         style={{ flex: 1, backgroundColor: 
         tabBarStyle.backgroundColor }}
          >
          <TopTabNavigator
              {...props}
              screenStyle={screenStyle}
              cardStyle={cardStyle}
              popularLeagueCardStyle={popularLeagueCardStyle}
            />
          </View>
        )}
      </BottomTab.Screen>
      <BottomTab.Screen
        name="Stats"
        options={{
          headerStyle: {
            backgroundColor: cardStyle.cardBackgroundColor,
          },
          headerTitleStyle: { color: screenStyle.color },
        }}
      >
        {(props) => (
          <Stats
            {...props}
            screenStyle={screenStyle}
            cardStyle={statsCardStyle}
            popularLeagueCardStyle= 
       {popularLeagueCardStyle}
          />
        )}
      </BottomTab.Screen>
      <BottomTab.Screen
        name="Settings"
        options={{
          headerStyle: screenStyle, // Apply the 
         screenStyle to headerStyle
          headerTitleStyle: { color: screenStyle.color 
       },
        }}
        component={SettingsScreen}
      />
    </BottomTab.Navigator>
  );
};

Sample Bottom tab screen ( Stats.js) code

export default function Stats({cardStyle, screenStyle,popularLeagueCardStyle}) {
 const { backgroundColor, color, iconColor } = screenStyle;
  const { cardBackgroundColor, cardColor, cardiconColor } = cardStyle;
  const { popularCardBackgroundColor  } = popularLeagueCardStyle;

return(
  <View style={[styles.container, {backgroundColor:backgroundColor}]}>
// some views rendered
</View>
);

}

So, when navigating through the stats,setting and other Bottom tabs screen,the process is very slow. Please help

vs code showing error of node:event:491 during deployment of server in react [closed]

after installing node modules in vs code using npm install
then trying to use command npm start
after that this error occuring

im trying to start deployment server on local host but when giving command npm start its showing error
im expecting to deploy my project on local host……………………………………………………………………………………………………………………………………………………………………………………….